How do I create a new entity SQL schema?

Table of Contents

Naming conventions and idempotency rules are in SQL entity schema patterns. The compass-codegen-add-sql-schema skill drives this process; codegen is mandatory.

1. Question

How do I create the SQL schema for a new entity in ORE Studio?

2. Answer

  1. Confirm the org model under projects/ores.<component>/modeling/ carries #+type: ores.codegen.entity (UUID PK) or ores.codegen.junction (composite text PK). Scaffold it with compass add entity_org if it does not exist yet.
  2. Generate the SQL schema file (written directly to projects/ores.sql/):
./compass.sh codegen entity generate <entity> --address ores.sql.schema
  1. Register the new schema file in the orchestration script for the component (typically projects/ores.sql/scripts/{component}_schema.sh).
  2. Add RLS policies for the new entity. Every entity table with tenant_id needs a tenant isolation policy; tables that also have party_id need a party isolation policy on top. Add them to projects/ores.sql/create/{component}/{component}_rls_policies_create.sql (create the file if the component has none) and register it in projects/ores.sql/create/rls/rls_create.sql. See SQL entity schema patterns §Row-Level Security for the exact policy templates.
  3. Run schema validation:
./projects/ores.sql/utility/validate_schemas.sh
  1. Raise a PR with title [sql] Add {entity} schema.

3. Tested by

./projects/ores.sql/utility/validate_schemas.sh — verifies idempotency and naming conventions for all schema files.

4. See also

Emacs 29.3 (Org mode 9.6.15)