Some reversible migrations cannot be reversed in practice?

16 views
Skip to first unread message

pa...@qwil.co

unread,
Apr 19, 2017, 4:18:31 PM4/19/17
to Django users
I've just hit a tricky migration case, and I'd like to check I'm not missing something. The summary is that merge migrations make it possible to add migrations which cannot be unapplied, even if they are the latest migration to be run.

With the migration graph:

M1
|
+------+
|      |
M2a   M2b
|      |
+------+
|
M3(merge)

Now, as far as a can tell, if I want to revert M2b, I have to run `manage.py migrate app M1`. If M2a is not reversible, then it's impossible to un-apply M2b, even though the dependency graph would allow it. Or to consider another pathological case, imagine a long-running series of deployed migrations (M2a, M3a, M4a, ...) instead of an immediate merge commit; the M2b migration could be impossible to revert without reverting many other migrations in the other branch, which could delete user data if run in production.

It seems there's a missing command, `manage.py revertmigration M2b`, which would walk the dependency graph backwards to figure out which later migrations needed to be unapplied (in this case M2b and M3). Absent this command, it seems that merge migrations aren't safe to use, and should be avoided.

Am I missing something here? Appreciate any insights or workarounds anyone has on this subject.
Reply all
Reply to author
Forward
0 new messages