davedevelopment / phpmig

Simple migrations system for php
Other
568 stars 93 forks source link

Allow out of order migrations #102

Closed clphillips closed 8 years ago

clphillips commented 8 years ago

One huge improvement to migration handling when you're dealing with pull requests which may be merged out of order is the ability to run migrations out of order.

What does that mean exactly? It means finding and sorting all migrations which exist but have not been processed, then processing those migrations (in order).

For example. Assume we have the following migrations in our database

version
20160314000000
20160315000000
20160316000000

Now suppose we merge a new migration in. It's called 20160315060000_SomeTask.php. We can't run it. Instead we have to rollback to 20160315000000, then migrate forward again. This is a huge pain.

With a setting (disabled by default) allowing any migration to be processed that hasn't been processed we'd have:

version
20160314000000
20160315000000
20160316000000
20160315060000
davedevelopment commented 8 years ago

I'm not sure I follow, I thought the lib would run through any migrations that haven't been run yet?

davem@wes:www:master$ phpmig status

 Status   Migration ID    Migration Name 
-----------------------------------------
     up  20160106201419  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160108115524  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160113120751  XXXXXXXXXXXXXXXXXXXXXXXXXx
   down  20160114080443  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160115224616  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160119100302  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160119210838  XXXXXXXXXXXXXXXXXXXXXXXXXx
   down  20160126110050  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160129212040  XXXXXXXXXXXXXXXXXXXXXXXXXx
   down  20160129222803  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160205213320  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160205213517  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160223200704  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160308212217  XXXXXXXXXXXXXXXXXXXXXXXXXx
     up  20160309150225  XXXXXXXXXXXXXXXXXXXXXXXXXx

davem@wes:www.childcare.co.uk:master$ phpmig migrate
 == 20160114080443 XXXXXXXXXXXXXXXXXXXXXXXXXx migrating
 == 20160114080443 XXXXXXXXXXXXXXXXXXXXXXXXXx migrated 0.0050s
 == 20160126110050 XXXXXXXXXXXXXXXXXXXXXXXXXx migrating
 == 20160126110050 XXXXXXXXXXXXXXXXXXXXXXXXXx migrated 0.0047s
 == 20160129222803 XXXXXXXXXXXXXXXXXXXXXXXXXx migrating
 == 20160129222803 XXXXXXXXXXXXXXXXXXXXXXXXXx migrated 0.0068s 
davem@wes:www.childcare.co.uk:master$ 
aik099 commented 8 years ago

Probably @clphillips have migrations that depend one on another and wants them to run in order they were created.

davedevelopment commented 8 years ago

But if they depended on each other, how could they later migrations have been run already...?

aik099 commented 8 years ago

Then I guessed wrong maybe.

clphillips commented 8 years ago

Hm... My previous testing has shown that only migrations after the latest stored migration are run when performing phpmig migrate. I'll see if I can duplicate, because it would be super sweet if any and all un-run migrations are run during phpmig migrate.

clphillips commented 8 years ago

Awesome! Previous un-run migration are run during phpmig migrate. Not sure why I was having trouble before. Maybe I ran into a database error during the migration or something.