lembadm/yii2-migration-helper Yii2 migration helper

extensionhelpermigration

MigrationHelper

MigrationHelper helps to up/down migrations from PHP script

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist lembadm/yii2-migration-helper "*"

or add

"lembadm/yii2-migration-helper": "*"

to the require section of your composer.json file.

Usage

To use this extension, simply add the following code in your application configuration:

return [
    //....
    'components' => [
        'migration' => [
            'class' => 'lembadm\migration\MigrationHelper',
            'migrationTable' => '<migrationTable>',
            'idleTimeout' => '<idleTimeout>',
            'timeout' => '<timeout>',
        ],
    ],
];

Apply new migrations

Synchronously

try {
    $process = Yii::$app->migration->up();
    echo $process->getOutput();
} catch (ProcessFailedException $e) {
    echo $e->getMessage();
}

Async

$process = Yii::$app->migration->upAsync();
while ($process->isRunning()) {
    // waiting for process to finish
}

or

$process = Yii::$app->migration->upAsync();
// ... do other things
$process->wait(function ($type, $buffer) {
    echo (Process::ERR === $type)
        ? 'ERR > '.$buffer
        : 'OUT > '.$buffer;
});

Apply module migrations

All same but need to specify path to module: $migrationPath Path to migrations (--migrationPath argument for yii migrate/up command).

$process = Yii::$app->migration->up('<pathToModule>');

Downgrades the application by reverting old migrations.

Synchronously

try {
    $process = Yii::$app->migration->down();
    echo $process->getOutput();
} catch (ProcessFailedException $e) {
    echo $e->getMessage();
}

Async

$process = Yii::$app->migration->downAsync();
while ($process->isRunning()) {
    // waiting for process to finish
}

or

$process = Yii::$app->migration->downAsync();
// ... do other things
$process->wait(function ($type, $buffer) {
    echo (Process::ERR === $type)
        ? 'ERR > '.$buffer
        : 'OUT > '.$buffer;
});

Apply module migrations

All same but need to specify path to module: $migrationPath Path to migrations (--migrationPath argument for yii migrate/up command).

$process = Yii::$app->migration->downAsync('<pathToModule>');

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

No stable releases.

Comments



No stable releases.



MIT license
Stats
0 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
0 total downloads