Phalcon Database Migrate / Rollback

I would like to revert / discard changes made to the database as part of the Phalcon devtools migration command in case of upgrade problem.

In the migration file, it looks like this should be possible with the method public function down()

. However, I can't seem to get this to work. There is no obvious rollback command, only "generate" and "run" (as from Phalcon devtools 1.3.4).

I quickly looked at the devtools code on git, specifically the Migration.php code here: https://github.com/phalcon/phalcon-devtools/blob/master/scripts/Phalcon/Mvc/Model/Migration.php . There are calls for up()

, but not mentioned down()

.

What would be the recommended way to create a rollback function?

+3


source to share


1 answer


the documentation mentions

If you specify a target version, Phalcon will perform the required migrations until it reaches the specified version.

It refers to a parameter --version

that you can use in the execute migration command:

phalcon migration run --version=1.0.1

      



Depending on the current version of the database stored in .phalcon/migration-version

, it will use up or down to reach version 1.0.1

For example, given this command and suppose we have migrations 1.0.0, 1.0.1 and 1.0.2:

  • if migration version doesn't exist it will run up methods from migrations 1.0.0 and 1.0.1
  • if migration version is 1.0.2 it will run down method from 1.0.2 migration
0


source







All Articles