MigrationHelper helps to up/down migrations from PHP script
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.
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>',
],
],
];
try {
$process = Yii::$app->migration->up();
echo $process->getOutput();
} catch (ProcessFailedException $e) {
echo $e->getMessage();
}
$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;
});
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>');
try {
$process = Yii::$app->migration->down();
echo $process->getOutput();
} catch (ProcessFailedException $e) {
echo $e->getMessage();
}
$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;
});
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>');