Name: django-MacFly
Owner: PeopleDoc
Description: Output sql migrations for ahead of time schema changes.
Created: 2015-10-06 13:03:46.0
Updated: 2017-11-28 21:42:38.0
Pushed: 2015-12-22 13:18:05.0
Homepage: null
Size: 21
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Output sql migrations for ahead of time schema changes.
install django-MacFly
ython
ALLED_APPS += ['django_macfly']
On a develop environment, deploy the old (version N) code and run migrations. Then, deploy the new code (version N+1) without running the migrations.
Then run:
on manage.py sqlmigratefwd
Read the result, think, hack, do.
Here, at Peopledoc we found that:
Our strategy for schema migration is to run migrations ahead of time, the database is migrated to schema N+1 while the code is at N.
This strategy requires coding discipline (do not rename a DB Column, do not change a column type…) and we needed a tool that checks the code changes, warn us if the changes are not ZDD-friendly, and gather all (safe) SQL commands to make the migration.
This is NOT AT ALL an automatic migration tool. It's just a (dumb) HELPER. It outputs hints that you MUST read and understand. Your ahead-of-time migration will probably need DB triggers, query re-writing, default values and all sort of DBA voodoo stuff to work properly. MacFly DO NOT handle this. Candide use may eat your data and voids even the no-warranty-of-any-kind clause.
Basically it walks through pending migration (using django migrate internals).
For each migration:
sqlmigrate
:sqlmigrate
remove default values for NOT NULL
columns. Here we need a SQL default
because the code doesn't know the column, and inserts would fail. Hence, sqlmigratefwd
doesn't drop defaultssqlmigratefwd
also issues a faked migration (an insert in django_migration
table).
So it's safe at deploy time to run migrate