Skip to content

Commit

Permalink
Merge pull request #494 from wikimedia/fix-pdo-init
Browse files Browse the repository at this point in the history
PDO: Move online schema creation behind feature flag
  • Loading branch information
glensc authored Feb 11, 2024
2 parents c3b042b + 3e87168 commit 80a6298
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/Db/PdoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/ServiceProvider/PdoStorageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 80a6298

Please sign in to comment.