Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i run all migrations for all plugins in cakephp 3?

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?

like image 506
jurrieb Avatar asked Oct 30 '22 12:10

jurrieb


1 Answers

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.

like image 159
drmonkeyninja Avatar answered Dec 11 '22 03:12

drmonkeyninja