How do I create a new entity SQL schema?

Table of Contents

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

Question

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

Answer

  1. Create a JSON model under projects/ores.codegen/models/{component}/ using *_domain_entity.json (UUID PK) or *_junction.json (composite text PK) naming.
  2. Generate the SQL schema file (written directly to projects/ores.sql/):
./compass.sh codegen entity generate <entity> --profile sql
  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.

Tested by

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

See also

Emacs 29.1 (Org mode 9.6.6)