Skip to content
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

Add 'UseMigrationLock' flag to acquire exclusive lock while performing migrations for Postgres #596

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

zapling
Copy link

@zapling zapling commented Nov 18, 2024

First I'd like to thank you @amacneil for all the hard work, been using this project for years now and it's the best tool for the job.

We currently have a client who are performing migrations from within their code using the dbmate library to do so. They have multiple components that are run as their own deployment in kubernetes, meaning each component is peforming a migration. When we do new deployments of this application, each component starts up and migrations are attempted at the same time, resulting in race conditions.

We have resolved this by adding a new DriverMigrationLock interface, that the Postgres driver implements. It uses an postgres advisory lock within a database transaction to prevent any other dbmate instance from migrating while the lock is active.

The use of the exclusive lock is currently opt-in by using the UseMigrationLock field on the DB struct.

I feel like this might be something more people would like to have, who might be in a similar position.

I have added a few tests for the Postgres driver, I can add more, but unsure what exactly what we should test? It might be nice to have one test for the DB struct, if so, could you point me in the right direction?

@zapling zapling changed the title Add 'UseMigrationLock' flag to aquire exlusive lock while performing migrations for Postgres Add 'UseMigrationLock' flag to acquire exlusive lock while performing migrations for Postgres Nov 18, 2024
@zapling zapling changed the title Add 'UseMigrationLock' flag to acquire exlusive lock while performing migrations for Postgres Add 'UseMigrationLock' flag to acquire exclusive lock while performing migrations for Postgres Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants