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

Automatically run migrations during Heroku's "Release" Phase #1931

Merged
merged 4 commits into from
Apr 20, 2017

Conversation

dstufft
Copy link
Member

@dstufft dstufft commented Apr 19, 2017

This change ensures that only one alembic command can be run at any one time (and they will queue up behind the currently running command waiting to acquire the lock). This means that two independently run migration commands won't have one of them failing to commit the transaction.

In addition this uses the Heroku Release Phase to run the database migrations and deploy the Fastly configuration automatically when a new release is created. That new release won't deploy until after the release command has been run (and if it unsuccessful, the deploy will fail).

This will prevent the Fastly config from slowing down start up as well.

One important caveat here is that obviously with an already running website both the Fastly and the DB migrations will have to not break compatibility with the currently running code unless we're fine with getting errors during that window.

Fixes #661

@dstufft dstufft requested a review from ewdurbin April 19, 2017 17:31
Copy link
Member

@ewdurbin ewdurbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for pg_advisory_lock.

i don't have any suggestions on a better approach!

@ewdurbin
Copy link
Member

the only suggestion i'd have is documenting the requirement of backwards compatible database migrations (at least on a step by step basis) in the developer docs. similar for fastly configuration.

dstufft added 4 commits April 20, 2017 12:32
Two different alembic commands attempting to run concurrency may end
up fighting over who gets to apply a migration. Since we use
transactions typically what will happen is that they'll both run
but the later one will fail to commit the transaction and return a
error code.

Instead, we would like it to wait until the other command has ran and
then see nothing needs to be done, and return a success code.
@dstufft dstufft merged commit d906f4a into pypi:master Apr 20, 2017
@dstufft dstufft deleted the auto-migrate branch April 20, 2017 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants