Allow collection.Version() calls during a migration #89
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.
As of today, if you try to call
collection.Version(db)
when a migration is running, it will wait for theLOCK TABLE gopg_migrations
lock to be released before returning.If you have long-running migrations (e.g.
CREATE INDEX CONCURRENTLY ...
that is running in background) and other pieces of code that rely on getting the current database version, this becomes a problem.I stumbled upon this issue when trying to start services that checked the current database version at startup while a long-running migration was executed.
To allow this use case, we can update the lock command to
LOCK TABLE ? IN EXCLUSIVE MODE
which allows concurrent SELECT commands to be run on the migrations table, while still forbidding other operations.From the documentation:
See:
I've targeted the
v7
branch for this patch, sincev8
is not released yet. I can update this pull request if this is not the best target.Thanks,