fix(migrations): renumber duplicate journal idx 47#1415
Open
jakebromberg wants to merge 1 commit into
Open
Conversation
The drizzle journal carried two entries at idx 47: `0046_cdc_notify_triggers` and `0047_replica-identity-for-pkless-tables`. Drizzle-kit derives snapshot filenames from idx, so the duplicate left `drizzle-kit drop` and any tooling that pairs SQL files to snapshots working off ambiguous bookkeeping for one of the two. The runtime migrator keys on `tag` so apply order was always well-defined, but the hazard had been silent under #590's allowlist. The fix keeps `0046_cdc_notify_triggers` at idx 47 (its natural slot after `0045_*` at idx 46) and renumbers `0047_replica-identity-for-pkless-tables` to idx 48, shifting every subsequent entry +1. Snapshot files were renamed to match the new idx assignments (chain UUIDs unchanged, so Check 6's prevId walk is unaffected). The `.sql` files were not touched — applied-hashes.json keys on tag, so Check 11 stays green. `scripts/validate-migrations.mjs` Check 5 was tightened to assert strict monotonic increase across the journal (subsuming the older uniqueness check). Tests in `validate-migrations.test.ts` were updated for the post-renumber state, including a positive non- monotonic-without-collision case so the new invariant has its own regression guard. The `HISTORICAL_DUPLICATE_IDXS` allowlist is now empty; `HISTORICAL_MISSING_SNAPSHOT_IDXS` shifted +1 for every entry above idx 47. Schema-shape tests that resolved migration .sql files by idx (`schema.artist-search-alias.test.ts`, `schema.concerts.test.ts`) were switched to tag-prefix matching so they survive future renumbers without further edits. Closes #1131
4 tasks
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.
Summary
shared/database/src/migrations/meta/_journal.jsoncarried two entries atidx: 47(0046_cdc_notify_triggersand0047_replica-identity-for-pkless-tables). Drizzle-kit derives snapshot filenames from idx, so the duplicate leftdrizzle-kit dropand any tooling that pairs SQL files to snapshots working off ambiguous bookkeeping for one of the two. The runtime migrator keys ontag(drizzle'sreadMigrationFilesonly readstag+when+breakpoints), so apply order was always well-defined — but the structural hazard had been silent under Regenerate Drizzle migration snapshots so drizzle:generate produces a clean diff (DoD #3 of WXYC/wxyc-shared#82) #590's allowlist.0046_cdc_notify_triggerskeeps idx 47 (its natural slot after0045_*at idx 46).0047_replica-identity-for-pkless-tablesmoves from idx 47 → 48, and every subsequent entry shifts +1. Snapshot files were renamed viagit mvto match the new idxs; the chain UUIDs (id/prevId) are unchanged so the prevId-chain walk in validate-migrations Check 6 is unaffected. The.sqlfiles were not touched —applied-hashes.jsonis keyed by tag (not idx), so Check 11 stays green and the deploy verifier's hash match continues to work.scripts/validate-migrations.mjsCheck 5 was tightened to assert strict monotonic increase across the journal (subsuming the older uniqueness check).HISTORICAL_DUPLICATE_IDXSis now empty;HISTORICAL_MISSING_SNAPSHOT_IDXSshifted +1 for every entry above idx 47. Two schema-shape tests that resolved migration .sql files by idx were switched to tag-prefix matching so they survive future renumbers without further edits.Test plan
npm run test:unit— 3152 tests pass (including the existing validate-migrations suite, all 44 tests, the schema.* shape tests, and a new regression test for the strict-monotonic-without-duplicate signal).npm run lint— 0 errors.npm run format:check— clean.npm run typecheck— clean.npm run lint:migrations—Migration journal validation passed (92 entries, 0 warning(s)).drizzle-orm/migrator'sreadMigrationFiles({ migrationsFolder })loads all 92 entries successfully against the renumbered journal; folderMillis (when) values remain strictly monotonic, so drizzle's apply cursor stays well-defined.tests/integration/migrations.spec.js(drizzle:migrate is idempotent against the loaded fixture) — gated on Docker availability; runs in CI.migrate-dryrunGH job (paths-filter fordb-init) —scripts/dryrun-migrate.mjsagainst the latest RDS snapshot is the production-grade end-to-end check.Closes #1131