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
- Confirm the org model under
projects/ores.<component>/modeling/. Use#+type: ores.codegen.entityfor UUID-PK tables andores.codegen.junctionfor composite-text-PK association tables. - 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 - Register the generated file in the component orchestration script.
- Validate:
./projects/ores.sql/utility/validate_schemas.sh - Raise PR with title
[sql] Add {entity} schema. Usefeature-branch-managerto transition between phases andpr-managerto open each PR.
3. Recipes
- How do I create a new entity SQL schema? — step-by-step walkthrough.
4. Reference
- SQL entity schema patterns — naming conventions, suffix catalogue, idempotency patterns.
- ORE Studio Codegen — model schema and
--address ores.sql.schemadetails. - ORE Studio SQL Schema — full schema mental model and PostgreSQL setup.
- Entity lifecycle — layer ordering overview.
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 |