Codegen Add SQL Schema

Table of Contents

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.

How to use this skill

  1. Create a JSON model in projects/ores.codegen/models/{component}/. Use *_domain_entity.json for UUID-PK tables, *_junction.json for composite-text-PK association tables.
  2. Generate the SQL schema (output goes to projects/ores.sql/): cd projects/ores.codegen && ./run_generator.sh models/{component}/{entity}_domain_entity.json --profile sql
  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.

Recipes

Reference

Templates

Runs via --profile sql. 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.1 (Org mode 9.6.6)