How do I create a new entity?

Table of Contents

1. Question

How do I add a new domain entity to ORE Studio?

2. Answer

2.1. 1. Read the standard first

Every entity must conform to entity lifecycle before writing any code. That document specifies what each layer must contain and what the defaults are. Partial entities or disabled defaults without written rationale are not acceptable.

2.2. 2. Create the codegen model

Scaffold the org model:

./compass.sh add entity_org --component {component} --slug {entity} \
    --description "<one line>"

This writes projects/ores.<component>/modeling/ores.<component>.<entity>.org with #+type: ores.codegen.entity. Fill in the columns, the profile flags, and the knobs the meta-model requires.

If any of has_history, has_pagination, or detail_fields is absent or disabled, add a deviation_rationale_{dimension} key with a one-sentence justification before proceeding.

2.3. 3. Generate and integrate each layer

# SQL (table DDL, trigger, RLS, artefact table)
./compass.sh codegen entity generate <entity> --address ores.sql.schema

# C++ API and core (domain type, repository, service, handler)
./compass.sh codegen entity generate <entity> --address ores.cpp

Follow the compass-codegen-add-entity skill for CMakeLists integration, layer wiring, and PR checkpoints at each layer boundary.

2.4. 4. Validate

# SQL schema integrity
./projects/ores.sql/utility/validate_schemas.sh

# Component documentation
./projects/ores.codegen/validate_docs.sh

Ask the user to build the affected targets before raising each PR.

3. Script

See compass-codegen-add-entity skill for the full phase-by-phase execution guide and layer-specific skills for deep detail on each layer.

4. Tested by

Build and test suite for the component via compass build (not raw cmake --build): ./compass.sh build {component}.core.tests.

Emacs 29.3 (Org mode 9.6.15)