Repository navigation
feat(frontend): gate the drizzle migrations on being backward compatible - #451
Merged
Merged
Conversation
`templates/job-db-migrate.yaml` runs the drizzle migrator as a `helm.sh/hook: pre-install,pre-upgrade` Job. **Pre-upgrade means the old pod is still serving** — Helm applies the hook, waits for it, and only then touches the Deployment. So every migration in this tree has always been applied underneath live code, and nothing checked that it could be. The neighbouring Rust half makes the asymmetry exact. `job-tenant-migrate.yaml` is `post-upgrade` and says why in its own header: *"the objection that rules out a pre-upgrade hook for the control plane (the old pod still serves) does not apply here."* The control plane took that objection seriously and moved its migration into the pod's init container. It also cannot execute a breaking change at all — its reconciler emits `CREATE TABLE` for an absent relation and `ADD COLUMN` for an absent nullable column, and refuses the rest as `ERR_SCHEMA_BREAKING`. Drizzle emits whatever `drizzle-kit` generated. This is the missing half of that asymmetry, expressed in the only place it can be: the committed SQL. Not a blue/green feature — the hole is open today. **Two severities, because collapsing them produced a false positive on a migration that had already shipped, which is how the distinction got found.** *Hard breaks* — the old pod's SQL fails: `DROP COLUMN`, `DROP TABLE`, `DROP SCHEMA`, `RENAME`, `ALTER … TYPE`, `SET NOT NULL`, and `ADD COLUMN … NOT NULL` with no `DEFAULT`. The last one is the interesting line: WITH a default it is allowed, because the default is what keeps the old pod's existing `INSERT`s working — exactly where `er_entity_diff`'s `Severity` puts the boundary between `Safe` and `Breaking`. *Invariant swaps* — `DROP INDEX` and `DROP CONSTRAINT` do not break the old pod at all; they remove a guarantee its code assumes. The honest rule is not "never" but "replace it", so a swap is a finding only when the same migration adds nothing back. `0007_thick_cyclops.sql` is the worked example already in the tree: it drops three indexes and a primary key and adds the dataset-scoped replacements for all four, so its window is one transaction. Treating that as a hard break would have demanded a contract marker for something correct — and a marker demanded where it is not warranted is how an escape hatch becomes reflexive. **The escape hatch has to justify itself.** Removing a column is legitimate in TWO releases: N stops reading it, N+1 drops it. A migration opts out with `-- er-contract:` followed by prose naming what stopped reading the column and when. A bare marker is refused, because an escape hatch nobody has to justify is just an absent gate. Observed failing before being trusted, in every direction — 25 unit cases plus a live end-to-end run against a planted migration: - a hard break with no marker -> exit 1, naming the file and the statement - the same break with a BARE `-- er-contract:` -> still refused - the same break with a justified marker -> passes, and PRINTS the exemption and its reason so a reviewer sees what was waved through - an empty migration directory -> exit **2**, refusing to report success on having examined nothing Two of those cases caught a real bug in the first implementation: the reason reader walked past the comment block into the SQL statement, so any `ALTER TABLE …` padded a one-word reason over the length bar. The justification has to be prose a person wrote, not the statement it is excusing. Comments and string literals are stripped before matching, because a comment explaining a past `DROP COLUMN` would otherwise be read as one — the exact mistake `bff-envelope-contract.test.ts` records making in its first draft, where a comment quoting a historical bug matched as the bug. Wired into `pnpm check` beside the authz and upstream gates, and exposed as `pnpm migrations:check`. Verified: `pnpm check` green — 794 tests, line coverage 57.2% against a 48% floor. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin
force-pushed
the
bm/bluegreen-p6-drizzle-gate
branch
from
November 3, 2026 05:51
c298b57 to
6701819
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this is not a blue/green feature
templates/job-db-migrate.yamlruns the drizzle migrator as ahelm.sh/hook: pre-install,pre-upgradeJob. Pre-upgrade means the old pod is still serving — Helm applies the hook, waits for it, and only then touches the Deployment. So every migration in this tree has always been applied underneath live code, and nothing checked that it could be.The neighbouring Rust half makes the asymmetry exact.
job-tenant-migrate.yamlispost-upgradeand says why in its own header:The control plane took that objection seriously and moved its migration into the pod's init container. It also cannot execute a breaking change at all — its reconciler emits
CREATE TABLEfor an absent relation andADD COLUMNfor an absent nullable column, and refuses the rest asERR_SCHEMA_BREAKING. Drizzle emits whateverdrizzle-kitgenerated. This is the missing half of that asymmetry, expressed in the only place it can be: the committed SQL.Two severities
Collapsing them produced a false positive on a migration that had already shipped, which is how the distinction got found.
Hard breaks — the old pod's SQL fails:
DROP COLUMNSELECTnames that columnDROP TABLE/DROP SCHEMARENAMEALTER … TYPESET NOT NULLINSERTomits the columnADD COLUMN … NOT NULLwith noDEFAULTINSERTdoes not name the columnThat last line is the interesting one: with a default it is allowed, because the default is what keeps the old pod's existing
INSERTs working — exactly whereer_entity_diff'sSeverityputs the boundary betweenSafeandBreaking.Invariant swaps —
DROP INDEXandDROP CONSTRAINTdon't break the old pod at all; they remove a guarantee its code assumes. The honest rule isn't "never" but "replace it", so a swap is a finding only when the same migration adds nothing back.0007_thick_cyclops.sqlis the worked example already in the tree: it drops three indexes and a primary key and adds the dataset-scoped replacements for all four, so its window is one transaction. Treating that as a hard break would have demanded a contract marker for something correct — and a marker demanded where it isn't warranted is how an escape hatch becomes reflexive.The escape hatch has to justify itself
Removing a column is legitimate in two releases: N stops reading it, N+1 drops it. A migration opts out with
-- er-contract:followed by prose naming what stopped reading the column and when:A bare
-- er-contract:is refused. An escape hatch nobody has to justify is just an absent gate.Observed failing before being trusted
25 unit cases plus a live end-to-end run against a planted migration:
-- er-contract:Two of those cases caught a real bug in my first implementation: the reason reader walked past the comment block into the SQL statement, so any
ALTER TABLE …padded a one-word reason over the length bar. The justification has to be prose a person wrote, not the statement it's excusing.Comments and string literals are stripped before matching, because a comment explaining a past
DROP COLUMNwould otherwise be read as one — the exact mistakebff-envelope-contract.test.tsrecords making in its first draft, where a comment quoting a historical bug matched as the bug.Verification
pnpm checkgreen — 794 tests, line coverage 57.2% against a 48% floor.pnpm checkbeside the authz and upstream gates, and exposed aspnpm migrations:check.🤖 Generated with Claude Code