Skip to content

db-migration-problems: change an enum, split a table, add a foreign key - #12

Merged
sajonaro merged 1 commit into
on-call-rotafrom
db-migration-problems-2
Oct 3, 2026
Merged

sajonaro merged 1 commit into
on-call-rotafrom
db-migration-problems-2

Conversation

@sajonaro

@sajonaro sajonaro commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Stacked on #11 (base on-call-rota). Retarget to main once #11 merges.

Adds the second batch of db-migration-problems/: three directories built to the first batch's standard. Each has SQL steps read by writ sql, a safe plan, a shortcut and a README.

problem the shortcut's mistake route to the fault
change-an-enum/ writes 'archived' while r1, which cannot read it, still serves add-value → deploy-r2 → archive-t1
split-a-table/ switches reads once the backfill has started five steps, the longest in the collection
add-a-foreign-key/ adds the key NOT VALID mid-rollout, so the old code's deletes now fail deploy-r2 → add-not-valid

writ sql findings, asserted as they are:

  • CHECK … IN becomes an enumerated type, and REFERENCES becomes (fk …), as planned.
  • NOT VALID is read as an ordinary foreign key. The output is identical with or without it, --strict accepts it, and an orphan row in that file loads without complaint. VALIDATE CONSTRAINT is declined under --strict, so the clause that changes meaning is the one accepted silently. Worth a writ issue: --strict could decline NOT VALID too, since writ carries a constraint's presence, not its validation state.

A correction to the parent README: "the shortcut is always shorter" was not measured. Over all six, the shortest route to a finished migration is shorter in two (add-a-required-column 3 vs 5, rename-a-column 8 vs 9) and equal in four. The README now says "never slower", with the numbers. compare reports nothing LOST for any of the six, so check is the gate.

Cross-check: 57 → 63 properties (61 compared). ./run-tests.sh all: 305 checks, 0 failed.

🤖 Generated with Claude Code

…d a foreign key

change-an-enum: widening the CHECK is instant; the first WRITE of the new
value is the migration, and the shortcut writes it while r1 still reads.
split-a-table: dual write and backfill; the shortcut switches reads once the
backfill has started — five steps, the longest route in the collection.
add-a-foreign-key: NOT VALID spares the old rows, not the running code; adding
it mid-rollout makes the old release's deletes fail, in two steps.

writ sql reads CHECK … IN as an enum and REFERENCES as an arrow, as planned;
it reads NOT VALID as a plain foreign key (identical output, --strict accepts
it) while declining VALIDATE CONSTRAINT — asserted as found. The parent
README's "the shortcut is always shorter" is now what was measured: shorter in
two of six, never longer.

Cross-check 57 -> 63 properties (61 compared); 305 checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sajonaro
sajonaro merged commit e5ff072 into on-call-rota Oct 3, 2026
1 check passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant