phpmig icon indicating copy to clipboard operation
phpmig copied to clipboard

Application extended with method to check and install all missing migrations, not only newer ones

Open moroz1999 opened this issue 7 years ago • 4 comments

At the moment if some migrations are not installed, application can miss them if they have an older timestamp than the last installed migration. This can easily happen when a team works on different features having different migrations alltogether, and periodically feature branches get merged into master.

moroz1999 avatar Jun 06 '18 10:06 moroz1999

Doesn't the migrate command do this already?

davedevelopment avatar Jun 08 '18 10:06 davedevelopment

The only method in PhpmigApplication to install migrations is PhpmigApplication::up, which takes the timestamp (version) of the last installed migration and installs everything with a bigger timestamp (version). As far as I understood, there is no way to run the "migrate" command through PhpmigApplication class, and I use it for migrations installing through http calls.

moroz1999 avatar Jun 13 '18 12:06 moroz1999

The MigrateCommand should do this, unless I've misunderstood your problem.

Here's a screencap of it on my app:

Screenshot

davedevelopment avatar Jun 13 '18 12:06 davedevelopment

We are using PHPMig not from CLI, but by sending HTTP request to PHP script. This PHP script makes an instance of PhpmigApplication to install the missing updates. PhpmigApplication doesn't have the exact "migrate" command functionality, as in the CLI, it doesn't check the older missing migrations. This is exactly what's been added by our commit. Please take a look at PhpmigApplication::getMigrations : https://github.com/davedevelopment/phpmig/blob/master/src/Phpmig/Api/PhpmigApplication.php#L101 It doesn't check the missing migrations, it takes "from" and "to" parameters. So we've added two methods to Application: https://github.com/moroz1999/phpmig/blob/master/src/Phpmig/Api/PhpmigApplication.php#L228 https://github.com/moroz1999/phpmig/blob/master/src/Phpmig/Api/PhpmigApplication.php#L251 They don't rely only on the date, but also recheck all older migrations to get anything that's missing inbetween. Again, there is no such problem with CLI "migrate" command.

moroz1999 avatar Aug 17 '18 10:08 moroz1999