2018-01-16 21:26:59 +01:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
use Composer\Autoload\ClassLoader;
|
|
|
|
use Engelsystem\Application;
|
|
|
|
use Engelsystem\Database\Migration\Migrate;
|
|
|
|
use Engelsystem\Database\Migration\MigrationServiceProvider;
|
2020-05-11 23:20:28 +02:00
|
|
|
use Engelsystem\Exceptions\Handler;
|
|
|
|
use Engelsystem\Exceptions\Handlers\NullHandler;
|
2018-01-16 21:26:59 +01:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../includes/application.php';
|
|
|
|
|
|
|
|
/** @var $loader ClassLoader */
|
|
|
|
$baseDir = __DIR__ . '/../db/migrations';
|
|
|
|
|
|
|
|
/** @var Application $app */
|
|
|
|
$app = app();
|
|
|
|
$app->register(MigrationServiceProvider::class);
|
|
|
|
|
2020-05-11 23:20:28 +02:00
|
|
|
/** @var Handler $errorHandler */
|
|
|
|
$errorHandler = $app->get(Handler::class);
|
|
|
|
$errorHandler->setHandler(Handler::ENV_PRODUCTION, new NullHandler());
|
|
|
|
|
2018-01-16 21:26:59 +01:00
|
|
|
/** @var Migrate $migration */
|
|
|
|
$migration = $app->get('db.migration');
|
|
|
|
$migration->setOutput(function ($text) { echo $text . PHP_EOL; });
|
2018-08-30 16:07:50 +02:00
|
|
|
|
2019-07-21 20:38:07 +02:00
|
|
|
if (isset($argv[1]) && in_array(strtolower($argv[1]), ['help', '--help', '-h'])) {
|
|
|
|
echo PHP_EOL . 'Usage: ' . $argv[0] . ' [up|down] [one-step]' . PHP_EOL . PHP_EOL;
|
2018-08-30 16:07:50 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$method = Migrate::UP;
|
|
|
|
if (isset($argv[1]) && strtolower($argv[1]) == 'down') {
|
|
|
|
$argv = array_values($argv);
|
|
|
|
$method = Migrate::DOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
$oneStep = false;
|
|
|
|
if (isset($argv[2]) && strtolower($argv[2]) == 'one-step') {
|
|
|
|
$oneStep = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$migration->run($baseDir, $method, $oneStep);
|