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
- Create a JSON model in
projects/ores.codegen/models/{component}/. Use*_domain_entity.jsonfor UUID-PK tables,*_junction.jsonfor composite-text-PK association tables. - 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 - 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.
Recipes
- How do I create a new entity SQL schema? — step-by-step walkthrough.
Reference
- SQL entity schema patterns — naming conventions, suffix catalogue, idempotency patterns.
- ORE Studio Codegen — model schema and
--profile sqldetails. - ORE Studio SQL Schema — full schema mental model and PostgreSQL setup.
- Entity lifecycle — layer ordering overview.
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 |