From 7029bbb75fe48a9f7b4bf6fbb2070f9d14520aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 16 Sep 2023 20:29:55 +0200 Subject: [PATCH] install base database in MigrateDatabaseCommand --- src/Cli/MigrateDatabaseCommand.php | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Cli/MigrateDatabaseCommand.php b/src/Cli/MigrateDatabaseCommand.php index a2f371c..5d789ec 100644 --- a/src/Cli/MigrateDatabaseCommand.php +++ b/src/Cli/MigrateDatabaseCommand.php @@ -19,6 +19,8 @@ class MigrateDatabaseCommand extends Command { $db = \Container::$dbConnection; + $this->createBaseDb(); + $db->startTransaction(); $success = []; @@ -62,10 +64,8 @@ class MigrateDatabaseCommand extends Command return 0; } - private function readDir(string $type): array + private function createBaseDb() { - $done = []; - $migrationTableExists = \Container::$dbConnection->query('SELECT count(*) FROM information_schema.tables WHERE table_schema = \'' . $_ENV['DB_NAME'] . '\' @@ -73,16 +73,25 @@ class MigrateDatabaseCommand extends Command ->fetch(IResultSet::FETCH_NUM)[0]; if ($migrationTableExists != 0) { - $select = new Select(\Container::$dbConnection, 'migrations'); - $select->columns(['migration']); - $select->where('type', '=', $type); - $select->orderBy('migration'); + return; + } - $result = $select->execute(); + \Container::$dbConnection->multiQuery(file_get_contents(ROOT . '/database/mapguesser.sql')); + } - while ($migration = $result->fetch(IResultSet::FETCH_ASSOC)) { - $done[] = $migration['migration']; - } + private function readDir(string $type): array + { + $done = []; + + $select = new Select(\Container::$dbConnection, 'migrations'); + $select->columns(['migration']); + $select->where('type', '=', $type); + $select->orderBy('migration'); + + $result = $select->execute(); + + while ($migration = $result->fetch(IResultSet::FETCH_ASSOC)) { + $done[] = $migration['migration']; } $path = ROOT . '/database/migrations/' . $type;