Repository navigation
fix(migrate-ts): stop false CHECK drift on Postgres and compare literals as written - #498
Merged
Merged
Conversation
…als as written A one-value enum, presentIff and validators on varchar(n) columns reported drift after migrate had just built them, because Postgres stores IN (x) as = x, IS NOT DISTINCT FROM as NOT (IS DISTINCT FROM) and casts varchar columns to text. The normaliser also lower-cased and bracket-stripped quoted literals, so an enum member or regex case change read as clean. char(n) is no longer a text-family column for the (col)::text fold. Adds a Postgres round-trip over every generated CHECK shape.
… drift Covers the non-regex bpchar case on real Postgres and offline.
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.
What Changed
migrateemits: a one-elementx IN (v)(stored asx = v),a IS NOT DISTINCT FROM b(stored asNOT (a IS DISTINCT FROM b)), and(col)::textontext/varcharcolumns only.meta verify --db,migrate --from-dband offlinemigrate --dry-runno longer report false CHECK drift for these shapes.meta migratebrings it back.char(n)is no longer treated as text for the(col)::textfold, since its own operator sees the padding. Precedence changes are still not detected.Validation
Risk Assessment
✅ Low: The change is confined to the migrate-ts CHECK-expression comparator and its callers. It meets the intent and the recorded decisions, and its failure modes lean toward reporting drift rather than hiding it.
Testing
Stood up a disposable postgres:16 container and a scratch meta project, built the CLI from dist, and drove
meta migrate --applythenmeta verify --dbend to end. Clean on the generated one-value enum CHECK (st = 'Open') and presentIff CHECK (NOT (kind IS DISTINCT FROM 'principal')). Adversarial: enum case change Open→open and presentIff literal change principal→Principal both report drift; restoring metadata returns to clean. Ran the live-PG suites with MIGRATE_TS_PG_URL: pg-check-shapes-roundtrip, pg-regex-check-cast, lifecycle-pg all pass (15/15), plus the full migrate-ts package (1109 pass, 0 fail). Full serverbun test(all packages) did not complete within the 580s foreground limit, so the broad regression run is unfinished; the baseline ts-fast/ts-unit lane was not rerun. Unit-level guards (precedence limit, NOT-distinct nesting, literal-internal IS DISTINCT, bpchar cast) run only inside the migrate-ts unit suite; not driven live through the CLI and recorded as untested.Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
server/typescript- Full serverbun testdid not complete within the foreground time limit, so the complete regression suite has no result.scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchainsbun cli/dist/bin/meta.js init (scratch project)bun cli/dist/bin/meta.js migrate --slug init --db <pg> --applybun cli/dist/bin/meta.js verify --db <pg> (clean, enum + presentIff)adversarial: sed enum @values Open->open then verify --db (drift reported)adversarial: sed presentIff @equals principal->Principal then verify --db (drift reported)MIGRATE_TS_PG_URL=<pg> bun test packages/migrate-ts/test/integration/pg-check-shapes-roundtrip.test.ts pg-regex-check-cast.test.ts lifecycle-pg.test.ts (15 pass)MIGRATE_TS_PG_URL=<pg> bun test packages/migrate-ts (1109 pass, 0 fail)MIGRATE_TS_PG_URL=<pg> bun test (server, full) — timed out at 580s, not completed✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.