From 6b383be1cd6c1ab71e81dd98b1dd46e5817bf4ee Mon Sep 17 00:00:00 2001 From: Basilius Sauter Date: Fri, 8 Mar 2019 13:21:52 +0100 Subject: [PATCH] Added config to disable automatic database schema update. --- config/lotgd.yml | 1 + src/Bootstrap.php | 12 +++++++----- src/Configuration.php | 12 ++++++++++++ src/Console/Main.php | 6 ++---- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/config/lotgd.yml b/config/lotgd.yml index 1b49ef8..adee2a3 100644 --- a/config/lotgd.yml +++ b/config/lotgd.yml @@ -3,6 +3,7 @@ database: name: daenerys user: root password: + disableAutoSchemaUpdate: false game: epoch: 2016-07-01 00:00:00.0 -8 offsetSeconds: 0 diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 181c3c1..01aecda 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -66,7 +66,7 @@ class Bootstrap list($dsn, $user, $password) = $config->getDatabaseConnectionDetails($cwd); $pdo = $this->connectToDatabase($dsn, $user, $password); - $entityManager = $this->createEntityManager($pdo); + $entityManager = $this->createEntityManager($pdo, $config); $this->game = (new GameBuilder()) ->withConfiguration($config) @@ -159,7 +159,7 @@ class Bootstrap * @param \PDO $pdo * @return EntityManagerInterface */ - protected function createEntityManager(\PDO $pdo): EntityManagerInterface + protected function createEntityManager(\PDO $pdo, Configuration $config): EntityManagerInterface { $this->annotationDirectories = $this->generateAnnotationDirectories(); $this->logger->addDebug("Adding annotation directories:"); @@ -180,9 +180,11 @@ class Bootstrap } catch (DBALException $e) {} // Create Schema and update database if needed - $metaData = $entityManager->getMetadataFactory()->getAllMetadata(); - $schemaTool = new SchemaTool($entityManager); - $schemaTool->updateSchema($metaData); + if ($config->getDatabaseAutoSchemaUpdate()) { + $metaData = $entityManager->getMetadataFactory()->getAllMetadata(); + $schemaTool = new SchemaTool($entityManager); + $schemaTool->updateSchema($metaData); + } return $entityManager; } diff --git a/src/Configuration.php b/src/Configuration.php index 9272dc9..27c12d1 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -20,6 +20,7 @@ class Configuration private $databaseName; private $databaseUser; private $databasePassword; + private $databaseAutoSchemaUpdate; private $logPath; private $gameEpoch; private $gameOffsetSeconds; @@ -70,6 +71,12 @@ class Configuration $this->databasePassword = $passwd; $this->databaseName = $name; + if (empty($rawConfig['database']['disableAutoSchemaUpdate'])) { + $this->databaseAutoSchemaUpdate = true; + } else { + $this->databaseAutoSchemaUpdate = false; + } + $gameEpoch = $rawConfig['game']['epoch']; $gameOffsetSeconds = $rawConfig['game']['offsetSeconds']; $gameDaysPerDay = $rawConfig['game']['daysPerDay']; @@ -157,6 +164,11 @@ class Configuration return $this->databasePassword; } + public function getDatabaseAutoSchemaUpdate(): bool + { + return $this->databaseAutoSchemaUpdate; + } + /** * Return the path to the directory to store log files. * @return string The configured log directory path. diff --git a/src/Console/Main.php b/src/Console/Main.php index 31003d1..0f2d01a 100644 --- a/src/Console/Main.php +++ b/src/Console/Main.php @@ -8,10 +8,7 @@ use Symfony\Component\Console\Application; use LotGD\Core\Bootstrap; use LotGD\Core\Game; use LotGD\Core\Console\Command\{ - DatabaseInitCommand, - ModuleValidateCommand, - ModuleRegisterCommand, - ConsoleCommand + DatabaseInitCommand, DatabaseSchemaUpdateCommand, ModuleValidateCommand, ModuleRegisterCommand, ConsoleCommand }; /** @@ -42,6 +39,7 @@ class Main $this->application->add(new ModuleValidateCommand($this->game)); $this->application->add(new ModuleRegisterCommand($this->game)); $this->application->add(new DatabaseInitCommand($this->game)); + $this->application->add(new DatabaseSchemaUpdateCommand($this->game)); $this->application->add(new ConsoleCommand($this->game)); // Add additional ones