-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you run goose.Run("up") in parallel from multiple instances of application? #258
Comments
This is intended behaviour. E.g., however your application starts up, you'd run a container, or a binary, etc. to apply your migrations and upon success continue to rollout your application. I'd suggest decoupling your migrations from your main application. |
A workaround for me: for {
_, err := db.ExecContext(ctx, "CREATE TABLE goose_migrations_in_progress (dummy boolean)")
if err == nil {
break
}
log.Errorf("can't acquire lock to do migration, might be another one in progress: %s", err)
time.Sleep(time.Second)
}
defer func() {
_, err := db.ExecContext(ctx, "DROP TABLE goose_migrations_in_progress")
if err != nil {
log.Error(err)
}
}()
goose.SetLogger(log.Logger())
if err := goose.Run("up", db, dir); err != nil {
return errors.WithStack(err)
} Instead of creating table I've tried to use pg_advisory_lock but for some reason it was blocking migrations with |
Also maybe this lib would be better choice for me: https://github.com/golang-migrate/migrate/blob/master/FAQ.md#what-happens-if-two-programs-try-and-update-the-database-at-the-same-time |
There is a directive you can add to the migration file telling
This is the relevant bit of the docs:
|
Yes, I had that directive. Still |
I have below at the start of http server:
However I've noticed recently that if two instances of application run migrations at the same time, then one will fail trying to apply migration that was already applied by the other one. Looks like there is a race condition. I was under impression that this library solves this problem with some smart queries but looks like not?
The text was updated successfully, but these errors were encountered: