Repository navigation
Description
Found during #904. The reconciler's live read is (name, type, nullable) only (er-entity-diff LiveColumn), so a column added to an existing store via ADD COLUMN never receives the CHECK constraint the fresh-store DDL carries. Consequence: the dev/prod control store and a freshly bootstrapped one enforce different rules.
Live examples on any store that was healed rather than born on #805+: tags.kind should be CHECK (kind IN ('user','system')) and tags.apply_min_role should be CHECK (apply_min_role IN ('steward','admin')) — both are in the generated DDL (er-entities/ddl/postgres/tags.sql) and absent from a reconciled store. Writes through the API are validated, so the gap needs a direct SQL write to bite — same class as the unreadable-apply_min_role path #875 made fail-closed.
Related, smaller: the 0005_tag_kind fixup became redundant once #905 made the reconcile path handle NOT NULL-with-default itself. It is idempotent and ledgered, so retiring it is cosmetic — fold into this ticket or leave it as history.
Options
- Teach the differ about named CHECK constraints (read
pg_constraint, diff, add-missing as Safe). Scope creep: constraint introspection is a bigger surface than columns. - Per-column fixups when a healed column's CHECK matters (the path of least new machinery —
0005_tag_kindalready exists for the column; a sibling fixup could add the checks). - Accept and document: API-validated writes make the missing CHECK defense-in-depth only.
Verify
Reconciled store vs fresh store: \d public.tags shows the same constraints on both.
Product context (2026-11-26)
Why this matters for the API product: Operate safely. A healed control store accepts writes a fresh one rejects, so dev, prod and a new customer deployment enforce different rules. API-validated writes cover it today, so this is defense in depth.
Current state: Still reproduces, and the class is broader than tags. LiveColumn is still (name, type_name, nullable) (rust/crates/er-entity-diff/src/lib.rs:26-33). add_column_sql (rust/crates/er-entity-diff/src/migrate.rs:91-115) emits only type, NOT NULL and DEFAULT, with no CHECK and no REFERENCES. So every accepted_values column (42 CHECK ( clauses across the generated Postgres DDL) or FK column added after a store's birth lacks its constraint. tags.sql still carries both CHECKs. The 0005_tag_kind fixup is still registered (rust/crates/er-server/src/fixups.rs:111, :230). Its doc comment (fixups.rs:540-547) already accepts option 3 in writing: "enforcement is the route's."
Definition of done: as above ("Verify"), generalized: for every Postgres entity, a reconciled store and a fresh store report the same pg_constraint set of CHECK and FK constraints.
Dependencies / sequencing: None. Any new read on the pre-reconcile path must stay narrow (see #1290's fix). Constraint introspection belongs in the differ, not in a pre-reconcile read.
Size: option 1 about 1 engineer-week; option 3 about 0.1.
Activity
fix(schema): a healed control store enforces the fresh store's CHECK …