Added config to disable automatic database schema update.

This commit is contained in:
Basilius Sauter
2019-03-08 13:21:52 +01:00
parent d609f981aa
commit 6b383be1cd
4 changed files with 22 additions and 9 deletions
+1
View File
@@ -3,6 +3,7 @@ database:
name: daenerys
user: root
password:
disableAutoSchemaUpdate: false
game:
epoch: 2016-07-01 00:00:00.0 -8
offsetSeconds: 0
+7 -5
View File
@@ -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;
}
+12
View File
@@ -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.
+2 -4
View File
@@ -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