Skip to content

Commit

Permalink
Temp fix to apply migrations correctly to staging/prod DBs
Browse files Browse the repository at this point in the history
This one is pretty obscure

There are a couple of issues with third party plugin migrations we need to solve here:

1. https://github.com/aldryn/aldryn-video/blob/126580c04fc6c0c60d23361280d56bd5333f5c51/aldryn_video/migrations/0001_initial.py#L11-L12
   depends on `__latest__`
   (which is essentially bug in most cases for this reason). Having already
   applied `aldryn_video 0001` now means we can't apply `cms 0016`
   the `temp_migration_settings` file allows us to temporarily un-register
   `aldryn_video` by running
   `python manage.py migrate cms 0016 --settings foundation.temp_migration_settings`
   without either breaking the site or failing on
   `django.db.migrations.exceptions.InconsistentMigrationHistory: Migration aldryn_video.0001_initial is applied before its dependency cms.0016_auto_20160608_1535 on database 'default'.`
2. Some other migration relies on `easy_thumbnails 0001` but doesn't declare
   it as a migration dependency, so we need to run
   `python manage.py migrate easy_thumbnails` to avoid throwing
   `django.db.utils.ProgrammingError: relation "easy_thumbnails_source" does not exist`
3. Once we've done those we can run `python manage.py migrate`
   to apply the remaining issues without error

Once we've run this once on staging and once on production to migrate
the existing DBs correctly, we can do another commit to revert this change
and delete `temp_migration_settings`
and set CMD back to
`python manage.py migrate && python manage.py update_index && /usr/bin/supervisord`
before the next deploy.
  • Loading branch information
chris48s committed Aug 24, 2020
1 parent 1edbba7 commit 2349226
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ EXPOSE $PORT

RUN python manage.py collectstatic --noinput

CMD python manage.py migrate && python manage.py update_index && /usr/bin/supervisord
CMD python manage.py migrate cms 0016 --settings foundation.temp_migration_settings &&\
python manage.py migrate easy_thumbnails &&\
python manage.py migrate &&\
python manage.py update_index &&\
/usr/bin/supervisord
3 changes: 3 additions & 0 deletions foundation/temp_migration_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from settings import * # flake8: noqa
INSTALLED_APPS = list(INSTALLED_APPS)
INSTALLED_APPS.remove('aldryn_video') # flake8: noqa

0 comments on commit 2349226

Please sign in to comment.