For proper migration rollback (either through errors or manual operation), does one need to implement specific things in the migration to ensure this can be done?
For instance, if I only have change()
, which has updates, how will it know how to do the rollback? Should I implement up()
and down()
for consistency and to ensure completion of rollback capabilities?
Edit #1
I think I should have specified the following in my previous submission. My change()
migration has the following code:
public function change()
{
//rename values
$this->query("update table_name_here set name_en='new value en' name_fr='new value fr' where id = 7");
...
}
This is mentioned in the docs here:
https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
So, if your migration only uses actions in the
change()
method that are reversible, then you don't need to do anything else, Phinx can figure the required inverted commands out on its own.If however you're using actions that are not automatically reversible, either because they're not covered, or because your not using Phinx's Table API, but say for example custom raw SQL, then you have to make sure that you implement the UP/DOWN logic yourself, either using the
up()/down()
methods instead of thechange()
method (you cannot use both), or by checking$this->isMigratingUp()
in thechange()
method to conditionally run either UP or DOWN logic.