Skip to content

Instantly share code, notes, and snippets.

@dannyroberts
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannyroberts/476ede4b3558081136a3 to your computer and use it in GitHub Desktop.
Save dannyroberts/476ede4b3558081136a3 to your computer and use it in GitHub Desktop.
Backwargs migrations on staging

I started out trying to do something simple, remove the tf-perisistence branch of touchforms from staging.yml.

Things went well until I got this error

[hqdb0-staging.internal.commcarehq.org] sudo: /home/cchq/www/staging/python_env/bin/python manage.py migrate --noinput
[hqdb0-staging.internal.commcarehq.org] out: 2015-03-19 18:02:01,478 INFO Raven is not configured (disabled). Please see documentation for more information.
[hqdb0-staging.internal.commcarehq.org] out: GhostMigrations: 
[hqdb0-staging.internal.commcarehq.org] out: 
[hqdb0-staging.internal.commcarehq.org] out:  ! These migrations are in the database but not on disk:
[hqdb0-staging.internal.commcarehq.org] out:     <formplayer: 0003_auto__add_session>
[hqdb0-staging.internal.commcarehq.org] out:  ! I'm not trusting myself; either fix this yourself by fiddling
[hqdb0-staging.internal.commcarehq.org] out:  ! with the south_migrationhistory table, or pass --delete-ghost-migrations
[hqdb0-staging.internal.commcarehq.org] out:  ! to South to have it delete ALL of these records (this may not be good).
[hqdb0-staging.internal.commcarehq.org] out: 

Fatal error: sudo() received nonzero return code 1 while executing!

Requested: /home/cchq/www/staging/python_env/bin/python manage.py migrate --noinput
Executed: sudo -S -p 'sudo password:'  -u "cchq"  /bin/bash -l -c "cd /home/cchq/www/staging/code_root && /home/cchq/www/staging/python_env/bin/python manage.py migrate --noinput"

Aborting.

Having seen this kind of things a couple times before in the past, I did not dispair. This is a clear sign that you've run a migration (in this case formplayer 0003_auto__add_session) in some environemnt (in this case staging), and then switched to another branch that does not have that migration on it. In this case the tf-perisistence branch of touchforms had migration 0003 but master did not.

Fixing this (just because of a lack of tooling on our part) required a couple manual steps, but it wasn't too hard.

$ ssh hqdb0-staging.internal.commcarehq.org
me@hqdb0-staging$ sudo -iu cchq bash
cchq@hqdb0-staging$ cd /home/cchq/www/staging/code_root/submodules/touchforms-src/
cchq@hqdb0-staging$ git checkout tf-persistence  # go to a branch that has the 'missing' migration
cchq@hqdb0-staging$ cd ../..
cchq@hqdb0-staging$ source ../python_env/bin/activate  # activate the virtualenv
# this rewinds the last migration (0003)
# leaving you at 0002
cchq@hqdb0-staging$ ./manage.py migrate formplayer 0002

Then I reran the command to deploy to staging. Worked like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment