This is mentioned in the docs here:
Phinx 0.2.0 introduced a new feature called reversible migrations. This feature has now become the default migration method. With reversible migrations, you only need to define the up logic, and Phinx can figure out how to migrate down automatically for you. For example:
[...]
The following actions are reversible when done through the Table API in Phinx, and will be automatically reversed:
- Creating a table
- Renaming a table
- Adding a column
- Renaming a column
- Adding an index
- Adding a foreign key
[...]
If a command cannot be reversed then Phinx will throw an IrreversibleMigrationException when itβs migrating down. If you wish to use a command that cannot be reversed in the change function, you can use an if statement with $this->isMigratingUp() to only run things in the up or down direction.
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 the change()
method (you cannot use both), or by checking $this->isMigratingUp()
in the change()
method to conditionally run either UP or DOWN logic.