Phinx: Forgetting to call save()/create()/update() leaves migration log in a bad state

Created on 22 Jun 2020  路  3Comments  路  Source: cakephp/phinx

Writing a simple Phinx query but forgetting to call one of the save()/create()/update() leaves the migration log in an invalid state. The migration will fail with an error similar to the following.

RuntimeException: Migration has pending actions after execution!

However, Phinx will still write to the migration log as if the migration completed successfully. Subsequent migrations will not run the migration again, because it thinks it has already completed. Subsequent rollbacks will fail because the changes do not exist.

bug

All 3 comments

That exception gets thrown as part of the postFlightCheck on the AbstractMigration.php. The execution of the migration happens here:

https://github.com/cakephp/phinx/blob/15dbca29eb3110fdedcc63c674a779dc40f16017/src/Phinx/Migration/Manager.php#L379-L386

where we have:

  1. Run preFlightCheck
  2. environment->executeMigration

    1. setMigrateDirection



      1. Run up/down/change method as appropriate


      2. record migration in phinx log



  3. Run postFlightCheck

I would propose moving the preFlightCheck and postFlightCheck inside the environment->executeMigration function and so have the following set-up:

  1. environment->executeMigration

    1. Run setMigrateDirection

    2. Run preFlightCheck

    3. Run up/down/change method as appropriate

    4. Run postFlightCheck

    5. Record migration in phinx log

An added benefit to also fixing the above would be that one would now be able to utilize the migration direction in the preFlightCheck method similar to the postFlightCheck method.

Someone wants to make a PR for this?
Is is this BC enough or should we put this into the next major?

It must be BC safe because forgetting to call those methods is an error and will break your migration table. So nobody can be doing this successfully and relying on this behaviour. Enhancement is the wrong tag, this is a bug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sooners87 picture sooners87  路  3Comments

amcoho picture amcoho  路  4Comments

rquadling picture rquadling  路  4Comments

Bilge picture Bilge  路  4Comments

djpate picture djpate  路  5Comments