Database Migrations
make dev-migrate-create (drizzle-kit generate) diffs db/schema.ts against the latest
snapshot in drizzle/meta/ and writes a new NNNN_*.sql file plus an updated
drizzle/meta/NNNN_snapshot.json and drizzle/meta/_journal.json.
make test applies every migration to each released version’s database as well as to an empty one,
so a migration that only fails against populated data fails there — see
Release-upgrade tests.
Resolving migration conflicts
When two branches each add a migration, drizzle/meta/_journal.json and the latest
drizzle/meta/NNNN_snapshot.json conflict — both branches claim the same index. Don’t hand-edit
the conflicted JSON; regenerate it instead:
Move your own new
.sqlmigration file out of the way (e.g. to/tmp) so it doesn’t confusedrizzle-kit. Note its name.Restore
drizzle/meta/to the stable version (main), discarding your branch’s snapshot/journal changes —db/schema.tsis unaffected, only the generated meta files reset:# jj jj restore --from main -- drizzle/meta # Git git checkout main -- drizzle/metaRegenerate against the restored snapshot, in a real terminal (not piped/non-interactive — see below):
make dev-migrate-create NAME=<original-migration-name>--namegets you the right filename directly; without it you’d rename the auto-generated file afterward (keep drizzle-kit’s index, drop the random suffix). If your change looks like a column rename to drizzle-kit (e.g. drop one column, add another), it opens an interactive prompt asking whether to treat it as a rename or a create+drop — it needs a real TTY, so this step can’t run from a script or CI.Diff the regenerated
.sqlfile against the copy you moved aside in step 1. For a plain mechanical schema change they’ll match — delete the moved-aside copy. But if your original migration had hand-written SQL beyond whatschema.tsalone implies (a data backfill, a value transform, choosing “rename” over “create+drop”), the regenerated file won’t reproduce it — drizzle-kit only knows what it can infer from the schema diff. In that case keep the regenerateddrizzle/meta/*_snapshot.jsonand journal entry (they carry the correct index), but replace the regenerated file’s SQL body with your original hand-written SQL.Run
make dev-migrate-upto confirm the migration applies cleanly, then continue resolving the rest of the conflict as usual.