Skip to content

fix: squash drizzle migrations into one idempotent baseline (#713) - #837

Merged
hekataion merged 3 commits into
mainfrom
fix/713-migration-squash
Jul 24, 2026
Merged

fix: squash drizzle migrations into one idempotent baseline (#713)#837
hekataion merged 3 commits into
mainfrom
fix/713-migration-squash

Conversation

@hekataion

Copy link
Copy Markdown
Collaborator

Summary

The 19 migrations in drizzle/*.sql had drifted out of sync with the 8 snapshots under drizzle/meta/ (all with empty tables: {}), leaving the snapshot chain malformed and npm run db:generate broken.

With no external installs yet (only bardo, fully upgraded), re-syncing the metadata carefully is not worth it — this is a clean slate:

  • Delete all 19 old migrations and 8 malformed snapshots
  • Regenerate a single baseline from schema.ts
  • Hand-edit all 55 CREATE statements to use IF NOT EXISTS so existing installs run it as a no-op

Removes test/db-migrations.test.ts which tested in-place data migration through intermediate rename steps (0015/0016/0017) that no longer exist in the squashed chain.

Verification

  • npm run db:generate runs clean
  • Re-running on unchanged schema produces no new migration
  • Fresh DB builds full schema via db:migrate
  • Existing DB (simulated) runs baseline as no-op (IF NOT EXISTS)
  • All tests pass

Fixes #713

🤖 Generated with Claude Code

The 19 migrations in drizzle/*.sql had drifted out of sync with the 8
snapshots under drizzle/meta/ (all with empty `tables: {}`), leaving the
snapshot chain malformed and `npm run db:generate` broken.

With no external installs yet (only bardo, fully upgraded), re-syncing the
metadata carefully isn't worth it — so this is a clean slate: delete every
migration and snapshot and regenerate a single baseline from schema.ts.

drizzle-kit's SQLite dialect emits bare `CREATE TABLE`/`CREATE INDEX`, which
would fail on an install already at this schema. Every statement is hand-edited
to `IF NOT EXISTS` so bardo's populated DB runs the baseline as a no-op (drizzle
still applies it, since its `when` postdates bardo's last migration) while a
fresh DB builds the full schema. Verified both paths plus data survival.

Removes test/db-migrations.test.ts: it exercised in-place data migration
*through* the intermediate rename/retype steps (0015/0016/0017), slicing the
journal at those exact tags. The squash collapses those steps into the baseline,
so that scenario — a live DB upgrading across the renames, which bardo already
completed — no longer exists in the chain.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the fix label Jul 23, 2026
hekataion and others added 2 commits July 24, 2026 09:22
Explains why hand-written migrations break the Drizzle snapshot chain
and documents the idempotent baseline pattern.

Co-Authored-By: Claude <noreply@anthropic.com>
Ensures Claude Code coders see the rule without needing to
read drizzle/README.md first.

Co-Authored-By: Claude <noreply@anthropic.com>
@hekataion
hekataion enabled auto-merge (squash) July 24, 2026 15:16
@hekataion
hekataion merged commit be10ae6 into main Jul 24, 2026
10 of 11 checks passed
@hekataion
hekataion deleted the fix/713-migration-squash branch July 24, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken drizzle db:generate — snapshot metadata malformed/missing since 0007; re-sync schema history

2 participants