Skip to content

Apply migrations one transaction per migration - #86

Open
tominal wants to merge 1 commit into
alveusgg:mainfrom
tominal:fix/fresh-db-enum-migration
Open

Apply migrations one transaction per migration#86
tominal wants to merge 1 commit into
alveusgg:mainfrom
tominal:fix/fresh-db-enum-migration

Conversation

@tominal

@tominal tominal commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Another PR for another lil first-time setup friction!

drizzle-orm's migrate() runs all pending migrations in a single transaction. PostgreSQL refuses to use a newly added enum value in the transaction that added it (error 55P04), so on a fresh database the batch fails: migration 0013 adds capture_status 'dead' and 0017 indexes on it. Existing databases never hit this because they migrated incrementally, committing between runs.

Replace the built-in migrator with a small one that commits per migration, reproducing that incremental behavior. Bookkeeping still uses drizzle's drizzle.__drizzle_migrations table, so existing databases and drizzle-kit stay compatible. Verified on a fresh database: all 30 migrations apply with no 55P04, and a re-run applies none.

drizzle-orm's migrate() runs all pending migrations in a single transaction.
Postgres refuses to use a newly added enum value in the transaction that added
it (error 55P04), so on a fresh database the batch fails: migration 0013 adds
capture_status 'dead' and 0017 indexes on it. Existing databases never hit this
because they migrated incrementally, committing between runs.

Replace the built-in migrator with a small one that commits per migration,
reproducing that incremental behaviour. Bookkeeping still uses drizzle's
drizzle.__drizzle_migrations table, so existing databases and drizzle-kit stay
compatible. Verified on a fresh database: all 30 migrations apply with no 55P04,
and a re-run applies none.
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.

1 participant