question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent multiple migrations starting in parallel

See original GitHub issue

In 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:closed
  • Created 7 years ago
  • Comments:18 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
canton7commented, Nov 25, 2016

Right, v0.9.7 is out, which should fix this.

0reactions
canton7commented, Nov 23, 2016

Right! That approach works. I’m tidying up the docs and fixing the unit tests, then I’ll get it merged.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found