fix(pg-core): use hash-membership to skip applied migrations#5783
Open
truffle-dev wants to merge 1 commit into
Open
fix(pg-core): use hash-membership to skip applied migrations#5783truffle-dev wants to merge 1 commit into
truffle-dev wants to merge 1 commit into
Conversation
PgDialect.migrate gated the apply loop on `Number(lastDbMigration.created_at) < migration.folderMillis`. The gate skips a pending migration whose journal `when` is older than the max created_at already in __drizzle_migrations - which happens any time a feature-branch migration with an earlier timestamp lands after a main-branch migration. The skip is silent. Drop the order-by-limit-1 read, load all applied hashes, and gate on `!appliedHashes.has(migration.hash)`. Hash is what uniquely identifies a migration anyway; created_at was just a proxy. Closes drizzle-team#5769
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5769.
PgDialect.migrateselected only the latest applied row and gated each pending migration onNumber(lastDbMigration.created_at) < migration.folderMillis. The gate silently skips any pending migration whose journalwhenis older than the maximumcreated_atalready in__drizzle_migrations. This happens routinely when a feature-branch migration with an earlier timestamp lands after a main-branch migration, after a backport, or after rebasing a long-running branch.The fix loads all applied hashes into a
Setand gates on!appliedHashes.has(migration.hash). Hash already uniquely identifies a migration;created_atwas only ever a proxy.Regression test in
integration-tests/tests/pg/node-postgres.test.tsreproduces the scenario by applying a migration withfolderMillis: 2000then re-running migrate with that plus a second migration atfolderMillis: 1000; without the fix the older entry silently skips, with the fix both apply.Note for review scope: the same
order by created_at desc limit 1+lastDbMigration.created_at < migration.folderMillisshape exists inmysql-core/dialect.ts,singlestore-core/dialect.ts, and the per-drivermigrator.tsfiles for neon-http, xata-http, pg-proxy, mysql-proxy, sqlite-proxy, singlestore-proxy, libsql, expo-sqlite, d1, durable-sqlite, op-sqlite. Happy to follow up with a multi-dialect sweep if you want it in one place or separate PRs.