Codegen Add SQL Schema

Table of Contents

1. When to use this skill

When you need to add SQL tables, triggers, indexes, or reference data to the ORE Studio database for a new entity. This is the second layer in the entity lifecycle — the domain type must already exist (see domain-type-creator). For the full layer ordering see Entity lifecycle.

Codegen is mandatory. Hand-crafting SQL is only permitted when the entity pattern cannot be expressed in any existing template; in that case, extend the template first, then generate.

2. How to use this skill

  1. Confirm the org model under projects/ores.<component>/modeling/. Use #+type: ores.codegen.entity for UUID-PK tables and ores.codegen.junction for composite-text-PK association tables.
  2. Generate the SQL schema (output goes to projects/ores.sql/): cd projects/ores.codegen && ./codegen.sh generate --model <path-to-model>.org --address ores.sql.schema
  3. Register the generated file in the component orchestration script.
  4. Validate: ./projects/ores.sql/utility/validate_schemas.sh
  5. Raise PR with title [sql] Add {entity} schema. Use feature-branch-manager to transition between phases and pr-manager to open each PR.

3. Recipes

4. Reference

5. Templates

Runs via --address ores.sql.schema. Read the template directly for the authoritative implementation — do not reproduce it here.

Template Output
sql_schema_domain_entity_create.mustache projects/ores.sql/create/{component}/{component}_{entity_plural}_create.sql
sql_schema_notify_trigger.mustache projects/ores.sql/create/{component}/{component}_{entity_plural}_notify_trigger_create.sql
sql_schema_domain_entity_drop.mustache projects/ores.sql/drop/{component}/{component}_{entity_plural}_drop.sql
sql_schema_notify_trigger_drop.mustache projects/ores.sql/drop/{component}/{component}_{entity_plural}_notify_trigger_drop.sql

Emacs 29.3 (Org mode 9.6.15)