mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Make DB migrations fully automatic
This commit is contained in:
@@ -75,14 +75,11 @@ class GrocyDbMigrator
|
||||
|
||||
private static function ExecuteMigrationWhenNeeded(PDO $pdo, int $migrationId, string $sql)
|
||||
{
|
||||
if ($pdo->query("SELECT COUNT(*) FROM migrations WHERE migration = $migrationId")->fetchColumn() == 0)
|
||||
$rowCount = Grocy::ExecuteDbQuery($pdo, 'SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn();
|
||||
if (intval($rowCount) === 0)
|
||||
{
|
||||
if ($pdo->exec(utf8_encode($sql)) === false)
|
||||
{
|
||||
throw new Exception($pdo->errorInfo());
|
||||
}
|
||||
|
||||
$pdo->exec('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
|
||||
Grocy::ExecuteDbStatement($pdo, $sql);
|
||||
Grocy::ExecuteDbStatement($pdo, 'INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user