XBackBone/bin/migrate

42 lines
1.3 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
$firstMigrate = false;
if ($config['db']['connection'] === 'sqlite' && !file_exists(__DIR__.'/../'.$config['db']['dsn'])) {
touch(__DIR__.'/../'.$config['db']['dsn']);
$firstMigrate = true;
2018-04-28 12:20:07 +00:00
}
2019-11-19 11:32:58 +00:00
$db = new DB(dsnFromConfig($config), $config['db']['username'], $config['db']['password']);
2018-04-28 12:20:07 +00:00
$migrator = new Migrator($db, 'resources/schemas', $firstMigrate);
$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')) {
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);