XBackBone/bin/migrate

36 lines
1.1 KiB
Plaintext
Raw Normal View History

2018-04-28 12:20:07 +00:00
#!/usr/bin/env php
<?php
2019-09-04 19:43:43 +00:00
(PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 1) ?: die('Sorry, PHP 7.1 or above is required to run XBackBone.');
2018-04-28 12:20:07 +00:00
if (php_sapi_name() !== 'cli') {
die();
2018-04-28 12:20:07 +00:00
}
use App\Database\DB;
use App\Database\Migrator;
require __DIR__.'/../vendor/autoload.php';
$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
}
chdir(__DIR__.'/../');
2018-04-28 12:20:07 +00:00
2020-04-05 12:53:22 +00:00
$db = new DB(dsnFromConfig($config), $config['db']['username'], $config['db']['password']);
2018-04-28 12:20:07 +00:00
2020-04-05 12:53:22 +00:00
$migrator = new Migrator($db, 'resources/schemas');
$migrator->migrate();
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');
}
echo 'If you are upgrading from a previous version, please run a "php bin\clean".'.PHP_EOL;
echo 'Done.'.PHP_EOL;
exit(0);