The migration safety checklist (journal review + idempotency rules)
Two of my Drizzle migrations never ran in production. Nothing warned me. The migrator walks a journal file; my journal stopped at entry 13 while the folder had files 14 and 15, plus two different files both numbered 0015. Anything not listed in the journal is skipped. Silently. Production schema just… drifted from what the code expected.
Why this bug class is nasty
The migration files look present in the repo, code review sees the SQL, tests run against a freshly-created schema (which doesn't use the journal the same way), and prod quietly stays on the old schema until a query hits a missing column.
The checklist
- The journal is part of code review. Every PR adding a migration file must also show the
journal entry (
meta/_journal.jsonfor Drizzle). File without journal entry = does not run = request changes.
# CI check: every migration file has a journal entry
ls drizzle/*.sql | wc -l # files
jq '.entries | length' drizzle/meta/_journal.json # journal entries
# these two numbers must match; fail the build if not
- Guard against duplicate numbering. Two files named
0015_*is a merge-order accident waiting to happen. Add a CI uniqueness check on the numeric prefix; renumber the later one (I renamed my second 0015 → 0016 and added its journal entry). - Every migration is idempotent.
CREATE TABLE IF NOT EXISTS,ADD COLUMN IF NOT EXISTS, guarded index creation. Then re-running against an already-applied DB is a no-op instead of a crash, which makes recovery from journal drift safe:
ALTER TABLE users ADD COLUMN IF NOT EXISTS preferences jsonb;
CREATE INDEX IF NOT EXISTS idx_orders_user ON orders(user_id);
- Diff prod schema against expectations after deploy. A post-deploy job (or manual ritual)
that compares the live schema to what the ORM expects:
drizzle-kitintrospection, orpg_dump --schema-onlydiffed against a checked-in snapshot. Drift should page you, not surprise you. - Never hand-edit migration state without recording it. If you fix drift manually in prod, immediately reflect it in journal + files, or the next deploy re-breaks.
- Know your migrator's skip semantics. Every tool (Drizzle, Prisma, Flyway, Alembic) has a rule for "file exists but tracker doesn't know it." Learn whether yours errors, warns, or (like mine) silently skips.
- Test migrations against a copy of prod, not just empty DBs. Fresh-schema tests can't catch "never ran on existing data."
Steal this for your app
- Whatever your stack: find the source of truth your migration runner actually reads (journal, table, ledger) and put it under the same review scrutiny as the SQL.
- "Silently skipped" beats "loudly failed" as a horror story every time. Add loudness yourself via CI counts and post-deploy diffs.
- Idempotency is what makes every migration incident recoverable with "just run it again."
Run this on your codebase
Paste this into Claude Code in your repo:
Audit this repo's database migrations for silent-skip drift.
Find the migration runner's source of truth (journal file, tracking table, ledger) and compare it to the files on disk.
Count migration files versus tracked entries and flag any file the tracker does not know about.
Flag duplicate numeric prefixes on migration files, like two files both numbered 0015.
Check each migration for idempotency: IF NOT EXISTS guards on tables, columns, and indexes.
Determine whether this migrator errors, warns, or silently skips unknown files, and say which.
Propose a CI check that fails the build when file count and tracker entries diverge, plus a post-deploy schema diff.
Report findings as a checklist before changing anything.