Repository navigation
Conversation
Hold a session lock across migrator.up() and down() so a second replica waits and then applies only migrations that are still pending. PostgreSQL uses an advisory lock, MySQL and MariaDB use GET_LOCK, SQL Server uses sp_getapplock, and file-backed SQLite uses a lock file. Co-authored-by: Rahul Kashyap <itisrmk@users.noreply.github.com>
This branch has not been deployed
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.
Concurrent
migrator.up()/migrator.down()calls could both apply the same data migration. Each run now takes a lock for the whole call, then reads the executed set, so the waiter applies nothing that the first run already logged.pg_advisory_lock, held on a pinned connection.lock_timeoutandstatement_timeoutare cleared only while waiting, then restored.GET_LOCKwith a large positive timeout. MariaDB treats a negative timeout as invalid and would not lock.sp_getapplock.BEGIN IMMEDIATEon a second connection would block the migration's own writes.The lock name is the migrations table (schema + table). In-memory SQLite is not shared across connections. Oracle has no unprivileged session lock, so two Oracle processes can still race.
Closes #8456
Prepared with an AI coding agent.