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

Created on 8 Dec 2014  路  6Comments  路  Source: cakephp/phinx

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

All 6 comments

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.

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

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.

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

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshribakoff picture joshribakoff  路  15Comments

wpillar picture wpillar  路  97Comments

ahmarov picture ahmarov  路  27Comments

BardiaAfshin picture BardiaAfshin  路  14Comments

berarma picture berarma  路  16Comments