phinx icon indicating copy to clipboard operation
phinx copied to clipboard

Rollback on a specific migration, instead of stepping down to the target

Open jiMuBao opened this issue 11 years ago • 6 comments

Is is possible to only migrate down one of the earlier migration, rather than stepping down to it?

jiMuBao avatar Dec 08 '14 20:12 jiMuBao

hi @jiMuBao, no you can only rollback or migrate sequentially. This ensures consistency of your database. If you want to undo a specific migration I would suggest creating a new migration that reverts the change and migrating 'up' to it.

robmorgan avatar Dec 08 '14 21:12 robmorgan

I just changed datetime in the name of migration file I want to rollback to the be the last and everything worked just fine

mkhrystunov avatar Jan 13 '15 07:01 mkhrystunov

If your changes are independent then that would be OK, but if each subsequent migration is based upon changes in a previous migration, your sequence will be broken and rolling back further will be a problem.

rquadling avatar Jan 13 '15 08:01 rquadling

Still, the -force option or something like that for one specific migration could be very cool.

Sieg avatar Jan 28 '16 10:01 Sieg

This would be very useful! I have required this ability a few times now.

I have just accidentally migrated a migration which had a few digits missing from its ID. Because of this, Phinx thought this was a really old migration and put it to the bottom of the stack.

With the ability to rollback a specific migration I could have easily rolled it back, fixed its ID, and then re-migrated. Instead I had to manually run the down() SQL and manually delete it from the phinxlog table.

I understand that chronological order is important for keeping integrity but I think some kind of command is needed for undoing mistakes.

lenton avatar Aug 23 '16 15:08 lenton

V0.7.x-dev allows you to define the rollback order based upon execution order, not migration creation order, so, if you accidentally migrate now, rollback once will undo the one you just did, without needing to worry about IDs/dates.

rquadling avatar Aug 25 '16 10:08 rquadling