XBackBone/bin/migrate

46 lines
1.4 KiB
Plaintext
Raw Normal View History

2018-04-28 12:20:07 +00:00
#!/usr/bin/env php
<?php
2021-07-31 11:09:45 +00:00
((PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION > 7) ?: die('Sorry, PHP 7.2 or above is required to run XBackBone.');
if (PHP_SAPI !== 'cli') {
die();
2018-04-28 12:20:07 +00:00
}
use App\Database\Migrator;
2020-04-13 15:46:10 +00:00
use DI\ContainerBuilder;
require __DIR__.'/../vendor/autoload.php';
2020-04-13 15:46:10 +00:00
define('BASE_DIR', realpath(__DIR__.'/../').DIRECTORY_SEPARATOR);
$config = include __DIR__.'/../config.php';
2018-04-28 12:20:07 +00:00
if (!$config) {
die('config.php not found. Please create a new one.');
2018-04-28 12:20:07 +00:00
}
2020-04-13 15:46:10 +00:00
chdir(BASE_DIR);
$builder = new ContainerBuilder();
$builder->addDefinitions(BASE_DIR.'bootstrap/container.php');
$container = $builder->build();
$container->set('config', $config);
2018-04-28 12:20:07 +00:00
2020-04-13 15:46:10 +00:00
$db = $container->get('database');
2018-04-28 12:20:07 +00:00
2020-04-05 12:53:22 +00:00
$migrator = new Migrator($db, 'resources/schemas');
$migrator->migrate();
2020-04-13 15:46:10 +00:00
$migrator->reSyncQuotas($container->get('storage'));
2018-04-28 12:20:07 +00:00
if (isset($argv[1]) && $argv[1] === '--install') {
$db->query("INSERT INTO `users` (`email`, `username`, `password`, `is_admin`, `user_code`) VALUES ('admin@example.com', 'admin', ?, 1, ?)", [password_hash('admin', PASSWORD_DEFAULT), humanRandomString(5)]);
2018-04-28 12:20:07 +00:00
}
if (file_exists(__DIR__.'/../install') && (!isset($config['debug']) || !$config['debug'])) {
2020-04-06 10:55:58 +00:00
removeDirectory(__DIR__.'/../install');
}
2020-04-26 15:58:31 +00:00
echo 'If you are upgrading from a previous version, please run a "php bin' . DIRECTORY_SEPARATOR . 'clean".'.PHP_EOL;
echo 'Done.'.PHP_EOL;
2020-04-26 13:00:16 +00:00
exit(0);