Task: Migrate country to unified codegen model
This page documents a task in the Commission: country story. It captures the goal, current status, acceptance, and any notes or results.
Goal
Move * Validation function, * Insert trigger, coding_scheme, image_id,
and has_tenant_id from ores.refdata.country_table.org into
ores.refdata.country.org. Verify that the generated SQL artefact is
byte-identical to the existing table-pathway output. Delete
country_table.org. Blocked on steps 1–4 of the unified model migration
path (see Codegen model unification analysis).
Status
| Field | Value |
|---|---|
| State | DONE |
| Parent story | Commission: country |
| Now | Nothing. |
| Waiting on | Steps 1–4 of D2256981 (frontmatter detection, unified SQL template, merged parsers, variability guards). |
| Next | Nothing. |
| Last touched | 2026-06-27 |
Acceptance
- Generated SQL for country is byte-identical to the current table-pathway output before and after migration.
ores.refdata.country_table.orgis deleted.compass codegen entity generate country --profile sql --diffshows no differences.compass codegen entity generate country --profile qt --diffshows no differences.
Plan
(Implementation strategy. Written when work starts; key decisions
are distilled into the parent story's * Decisions at close, but the
plan itself stays — it is the historical record of what we did.)
Notes
PRs
| PR | Title |
|---|---|
| #1363 | [codegen] Consolidate SQL create to one template; migrate country; drop non-temporal family |
Review
| # | Comment summary | File | Decision | Notes |
|---|---|---|---|---|
| 1 | Dead :security_definer: attrs in 3 models |
reporting/scheduler models | Accepted | Removed in d1bce09e4; attr read nowhere after unconditional change |
| 2 | Coding-scheme validation is cross-tenant | sql_schema_domain_entity_create.mustache | Confirmed | Intentional: coding schemes are system-level reference data |
| 3 | is_image_id guard well-designed |
core.py | Ack | Positive |
| 4 | Natural-key composite unique index for country | refdata_countries_create.sql | Confirmed | Intentional, agreed semantic upgrade (ISO codes are unique) |
| 5 | facestudio binaries dilute diff | external/facestudio | Confirmed | Included at maintainer request; separate commit |
Result
Shipped via PR #1363.
country now generates from a single model file on the unified
domain_entity create path. ores.refdata.country_table.org deleted;
coding_scheme=/=image_id flags and the * Validation function section
folded into ores.refdata.country.org.
The task landed inside a larger consolidation (the unification "steps 1–4" it was blocked on were realised here rather than waited on):
- Unified create template.
sql_schema_domain_entity_create(via its org tangle source) now always emitssecurity definer set search_pathon the insert function, emits the coding-scheme soft-FK validation, and rendersimage_idonce via thehas_image_idflag (theis_image_idguard incore.pyskips it in the columns loop so it keeps canonical position while remaining a C++ column). - Non-temporal duplication removed. The entire unused non-temporal
family (21 SQL + C++ facet/archetype/template files + the
non-temporal*profile entries) was deleted; it was default-enabled for every domain entity and collided on the create output path. Temporality is deferred to anis_temporalvariability point, to be added when a genuinely non-temporal entity is first commissioned (see the updatedcodegen_unified_temporalstory).
Acceptance deviation (agreed with maintainer): the original "byte-identical
to the table-pathway output" bar was relaxed to "no unintended diffs."
Regenerated SQL preserves all correctness (security definer, coding-scheme
FK, change_reason validation) and differs from the old output only in the
agreed churn — header style, NEW=/=new casing, and a natural-key
composite unique index replacing two non-unique indexes (the ISO codes
are genuinely unique, so this is a stricter, correct constraint).
Out of scope / follow-up: rolling the same single-model treatment across the remaining dual-file entities (party_status, etc.) and the two table-only entities (currency, purpose_type); pre-existing country Qt generation drift (untouched here).