Skip to content

fix(migrations): renumber duplicate journal idx 47#1415

Open
jakebromberg wants to merge 1 commit into
mainfrom
fix/1131-journal-dup-idx
Open

fix(migrations): renumber duplicate journal idx 47#1415
jakebromberg wants to merge 1 commit into
mainfrom
fix/1131-journal-dup-idx

Conversation

@jakebromberg

Copy link
Copy Markdown
Member

Summary

  • shared/database/src/migrations/meta/_journal.json 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 (drizzle's readMigrationFiles only reads tag + 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_triggers keeps idx 47 (its natural slot after 0045_* at idx 46). 0047_replica-identity-for-pkless-tables moves from idx 47 → 48, and every subsequent entry shifts +1. Snapshot files were renamed via git mv to match the new idxs; the chain UUIDs (id/prevId) are unchanged so the prevId-chain walk in validate-migrations Check 6 is unaffected. The .sql files were not touched — applied-hashes.json is keyed by tag (not idx), so Check 11 stays green and the deploy verifier's hash match continues to work.
  • scripts/validate-migrations.mjs Check 5 was tightened to assert strict monotonic increase across the journal (subsuming the older uniqueness check). HISTORICAL_DUPLICATE_IDXS is now empty; HISTORICAL_MISSING_SNAPSHOT_IDXS shifted +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:migrationsMigration journal validation passed (92 entries, 0 warning(s)).
  • drizzle-orm/migrator's readMigrationFiles({ migrationsFolder }) loads all 92 entries successfully against the renumbered journal; folderMillis (when) values remain strictly monotonic, so drizzle's apply cursor stays well-defined.
  • Integration test tests/integration/migrations.spec.js (drizzle:migrate is idempotent against the loaded fixture) — gated on Docker availability; runs in CI.
  • migrate-dryrun GH job (paths-filter for db-init) — scripts/dryrun-migrate.mjs against the latest RDS snapshot is the production-grade end-to-end check.

Closes #1131

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
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.

Drizzle journal has two entries at idx 47, making snapshot path ambiguous

1 participant