davedevelopment / phpmig

Simple migrations system for php
Other
569 stars 92 forks source link

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

Open moroz1999 opened 6 years ago

moroz1999 commented 6 years ago

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.

davedevelopment commented 6 years ago

Doesn't the migrate command do this already?

moroz1999 commented 6 years ago

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.

davedevelopment commented 6 years ago

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

Here's a screencap of it on my app:

Screenshot

moroz1999 commented 6 years ago

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.