diff --git a/config/config.default.php b/config/config.default.php index 9d6a49c6..e7e8c035 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -18,6 +18,7 @@ 'pass' => getenv('XHGUI_PDO_PASS') ?: null, 'table' => getenv('XHGUI_PDO_TABLE') ?: 'results', 'tableWatch' => getenv('XHGUI_PDO_TABLE_WATCHES') ?: 'watches', + 'initSchema' => getenv('XHGUI_PDO_INITSCHEMA') ?: 'true', ], // Database options for MongoDB. diff --git a/src/Db/PdoRepository.php b/src/Db/PdoRepository.php index abbb8e55..5d1f48f6 100644 --- a/src/Db/PdoRepository.php +++ b/src/Db/PdoRepository.php @@ -34,7 +34,6 @@ public function __construct(PDO $pdo, string $driverName, string $table, string $this->driverName = $driverName; $this->table = sprintf('"%s"', $table); $this->tableWatches = sprintf('"%s"', $tableWatch); - $this->initSchema(); } public function getLatest(): array diff --git a/src/ServiceProvider/PdoStorageProvider.php b/src/ServiceProvider/PdoStorageProvider.php index 2e1f0cea..2ac7ffd5 100644 --- a/src/ServiceProvider/PdoStorageProvider.php +++ b/src/ServiceProvider/PdoStorageProvider.php @@ -48,12 +48,16 @@ public function register(Container $app): void }; $app[PdoRepository::class] = static function ($app) { - return new PdoRepository( + $repo = new PdoRepository( $app['pdo'], $app['pdo.driver'], $app['config']['pdo']['table'], $app['config']['pdo']['tableWatch'] ); + if ($app['config']['pdo']['initSchema'] === 'true') { + $repo->initSchema(); + } + return $repo; }; $app['searcher.pdo'] = static function ($app) {