Skip to content

fix(schema): a healed control store enforces the fresh store's CHECK and FK constraints (#914) - #1438

Merged
athvin merged 1 commit into
mainfrom
fix/914-constraint-parity
Nov 29, 2026
Merged

athvin merged 1 commit into
mainfrom
fix/914-constraint-parity

Conversation

@athvin

@athvin athvin commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Closes #914

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

A store the reconciler healed now carries the fresh store's CHECK and FK constraints.

  • The reconciler's ADD COLUMN carries REFERENCES and CHECK (… IN …).
  • Every boot's baseline replay adds any missing CHECK or FK on a constrained column. It checks by constraint kind and the one covered column, adds the constraint NOT VALID, then attempts VALIDATE. If historical rows violate it, the constraint stays in force for new writes and the boot continues. Postgres auto-names it exactly as the inline form does.

Why

Healed stores enforced fewer rules than fresh ones: tags.kind, tags.apply_min_role, and every constrained column added after a store's birth (42 CHECK clauses across the generated DDL). #914's done-when, generalised: a reconciled store and a fresh store report the same pg_constraint CHECK and FK set. Choice: convergence happens on every boot, by kind and column rather than by name, and NOT VALID first, so a dirty store can't block a deploy.

Proof

make check exit 0. New pg_constraint_parity drops every entity CHECK and FK from a fresh store, boots, and requires the identical set by name and definition. It then plants a violating tags row and requires the boot to succeed, the constraint to come back NOT VALID, and a new violating write to be refused. pg_schema_replay and the migration pg tests pass. The migrate unit test's pinned ADD SQL is updated, because it encoded the old behaviour.

Risk & rollback

Every deploy runs the new idempotent DO blocks at boot; on a store that already has the constraints they are catalogue lookups only. A constraint that existing data violates is added NOT VALID with a warning, never a boot failure. Rollback: git revert <merge-sha>; a constraint already added stays, which is the intended state.

Post-merge ledger

Closed by: agent · session Claude Code:24d16c2e-fec6-49d8-9797-060338df4848 on brians-MacBook-Pro · 2026-11-29T12:31:44Z

  • main is green with this change on it — the merge SHA, and the run
    that proves it. A later head SHA with this commit as an ancestor counts;
    a cancelled run with zero jobs does not: — 8997ed3, rust 46261216721 + frontend 46261216641 success
  • images built, or correctly never ran because nothing that goes into
    an image changed: — success, run 46261216701
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion: — run 46261602367 (DEPLOY_SHA 8997ed3) success; web-api-green logged 'er-server listening' at 12:21:17Z, after ensure_schema ran the new constraint DO blocks against the real dev store
  • the push-only surface no pull request can pre-test (deploy, drift,
    kind's nightly leg) is green, or knowingly red for a reason that is not
    this change: — infra success on 8997ed3
  • the board card reached Done through the automation rather than by
    hand, and the issue closed: — Reconciler-added columns never get their CHECK constraints — healed stores drift from fresh DDL #914 CLOSED by fix(schema): a healed control store enforces the fresh store's CHECK and FK constraints (#914) #1438 via automation
  • follow-ups are open for everything deferred here — numbers: — none
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned: — entity-framework-design records constraint convergence; a violating historical row leaves the constraint NOT VALID rather than failing a boot

Specific to this change

Context — plan, discoveries, measurements, files

Plan

Discoveries

Measurements

Files

Size: most of the diff is regenerated DDL. Each constrained column's DO block appears in both the .sql files and the compiled baseline.

🤖 Generated with Claude Code

…and FK constraints (#914)

A column the reconciler added to an existing store was born without the
CHECK (accepted_values) or REFERENCES the fresh DDL gives it inline. So
dev, prod and a freshly provisioned store enforced different rules:
tags.kind and tags.apply_min_role, and every constrained column added
after a store's birth (42 CHECK clauses across the generated DDL).

- The reconciler's ADD COLUMN now carries REFERENCES and CHECK, so a
  column added from now on is born constrained.
- Every boot's baseline replay adds any missing CHECK or FK per
  constrained column. It checks by constraint kind and the one column
  covered, adds it NOT VALID, then attempts VALIDATE; a historical
  violation leaves the constraint enforcing new writes rather than
  failing the boot. Postgres auto-names it as the inline form does. On a
  store without the column yet, it hits undefined_column and is deferred
  past the reconciler by ensure_schema's existing mechanism.

pg_constraint_parity drops every entity CHECK and FK from a fresh store,
boots again, and requires the same constraints by name and definition.
It then plants a violating tags row and requires the boot to succeed,
the constraint to return NOT VALID, and a new violating write to be
refused. The migrate test's pinned ADD COLUMN SQL is updated, because it
encoded the old, constraint-less behaviour. pg_schema_replay and the
migration pg tests pass. entity-framework-design records it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@athvin
athvin merged commit 8997ed3 into main Nov 29, 2026
44 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 29, 2026 12:14 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
marketing-preview — 6a9a8d17 Deployed Nov 29, 2026 by athvin via remove closed PR previews #166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconciler-added columns never get their CHECK constraints — healed stores drift from fresh DDL

2 participants