Search code examples
djangoherokudjango-south

Are there any downsides to doing a schema migration in my post_compile script


I have a django app running on heroku. I would like to run my South migrations before any code that depends on them goes live. After a quick review of current recommended practices I have found two suggested migration procedures.

Recommendation 1

  1. Commit and push all changes
  2. Run heroku run python manage.py migrate <APP_NAME> for each app

This suffers from having a period in between steps 1 and 2 where my code is assuming the latest schema is in place, but the db hasn't yet been updated.

Recommendation 2

  1. commit and push all database changes.
  2. Migrate.
  3. Push all code changes.

This solves the previous problem, but adds a lot more complexity to the deployment process, and some day I will mess this up.

Potential Solution?

It seems that I can avoid the problem in Recommendation 1 and keep my deployment to a single step by utilising a custom post_compile script that calls python $MANAGE_FILE migrate <APP_NAME> for each of my apps (in dependency order).

I have not seen this recommended anywhere, so my question is twofold. Can you see any potential problem with this approach, and do you have a better method?


Solution

  • If your application can afford some downtime, the easiest way seems to me to

    1. Pause your app using $ heroku maintenance:on
    2. Migrate all the apps at once with heroku run python manage.py migrate
    3. Restart your app: $ heroku maintenance:off

    Is it enough or do you have more complex needs ?