I know I can run bin/cake Migrations migrate --plugin MyPlugin
but I use 50+ plugins in my project and id liked to run all migrations in all plugins with one command is this possible?
As far as I am aware there is no straight forward command for running migrations for all plugins. However, you could put together a simple Shell script to do this.
You can retrieve a list of all the loaded plugins for an app using:-
$plugins = Plugin::loaded();
You can then run the migrations for each plugin using dispatchShell
which allows you to run a command from another Shell:-
$this->dispatchShell(
'migrations',
'migrate',
'-p',
$plugin
);
Each argument for the migration is passed as an argument to dispatchShell
.
So, putting all that together into a Shell script:-
<?php
// src/Shell/InstallShell.php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Core\Plugin;
class InstallShell extends Shell
{
public function plugins()
{
$plugins = Plugin::loaded();
foreach ($plugins as $plugin) {
$this->dispatchShell(
'migrations',
'migrate',
'-p',
$plugin
);
}
}
}
This script would be called like $ bin/cake install plugins
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With