Prevent multiple migrations starting in parallel
See original GitHub issueIn an environment with multiple instances of the same application, starting applications with the migration logic in the Startup will start multiple migrations that run in parallel. This can lead to race-conditions where one or more migrations may fail as they all have read that they should start migrations to bring the database up to the latest version.
I believe locking the versioninfo
table with an exclusive lock may be the answer to this problem as it will prevent other migrations starting if one has already locked the table in its transaction.
In Postgres: LOCK TABLE versioninfo IN ACCESS EXCLUSIVE MODE;
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (16 by maintainers)
Top Results From Across the Web
What happens if I run django migrations multiple times in ...
I've tested it by running the migrate command in parallel on a data migration, and Django will run the migration twice.
Read more >Decoupling database migrations from server startup: why and ...
Migrations on application startup are a bad idea · Problem #1: Parallel migrations lead to breakage · Problem #2: Mental coupling leads to ......
Read more >How to safely run database migrations with multiple app ...
Basically, all apps try to acquire the lock, only one of them gets it and runs the migrations, then unlocks. When the rest...
Read more >How to manage maximum concurrent migration batches
This article describes how to manage the number of concurrent migration batches in Microsoft Exchange Online in Microsoft 365.
Read more >How do you handle migrations ? : r/golang
We use postgres with gorm, currently we are using automigrate on app start to perform migrations. We have few concerns.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Right, v0.9.7 is out, which should fix this.
Right! That approach works. I’m tidying up the docs and fixing the unit tests, then I’ll get it merged.