Choosing migration with relative syntax

85 views
Skip to first unread message

Joakim Saario

unread,
Mar 11, 2016, 7:39:53 AM3/11/16
to Django developers (Contributions to Django itself)
Hello!

Today if you just need to unmigrate the n migrations before the last one you would
typically run `migrate <app> --list` and then `migrate <app> <migration_name>` where
`migration_name` is the migration you want to roll back to.

To reduce the steps of this procedure i think it would be nice to introduce
a syntax similar to how commits in for example git works. I.e `git show HEAD^`
for the previous commit and `git show HEAD~2` for the one before that.
It would also be good to support the `git show <commit_id>(^+)|(~\d)` variant
of this to be able to choose the origin.

For this to work good for the normal case, there need to be a magic word
that maps to the latest migration available and/or the latest applied migration.

I can clearly see a use case for this as I can imagine that the most common
operation besides applying all unmigrated migrations is to roll back n migrations.

Does this sounds like a good idea?

Markus Holtermann

unread,
Mar 11, 2016, 8:06:42 AM3/11/16
to Django developers (Contributions to Django itself)
Hi Joakim,

thank you for your proposal.

I don't think this is a good idea because you can easily accidentally undo too many migrations which would inevitably will result in data loss. You don't have the data loss problem in Git as you can always recover by using `git reflog` to go back and e.g. undo an incorrect rebase. However, when you remove a field from a database table the data is pretty much lost.

Cheers,

/Markus

Joakim Saario

unread,
Mar 11, 2016, 8:18:51 AM3/11/16
to Django developers (Contributions to Django itself)
You can always have a y/N-question to limit these cases. Though, I think this is a problem as it is right now too, because you can always do a typo.

/Joakim

Marc Tamlyn

unread,
Mar 31, 2016, 1:53:24 AM3/31/16
to django-d...@googlegroups.com

I actually think this would be super useful if we can make it make sense (HEAD~ with merges..). "Undo the migration I just did" is a common operation in development.

M

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/46b90e2f-e14d-41c9-8ac8-f7758e3a3d46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages