mirror of
https://github.com/grocy/grocy.git
synced 2025-08-21 04:43:32 +00:00
Use transactions for database migrations
This commit is contained in:
@@ -48,9 +48,21 @@ class DatabaseMigrationService extends BaseService
|
|||||||
$rowCount = $this->getDatabaseService()->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn();
|
$rowCount = $this->getDatabaseService()->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn();
|
||||||
|
|
||||||
if (intval($rowCount) === 0)
|
if (intval($rowCount) === 0)
|
||||||
|
{
|
||||||
|
$this->getDatabaseService()->GetDbConnectionRaw()->beginTransaction();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
$this->getDatabaseService()->ExecuteDbStatement($sql);
|
$this->getDatabaseService()->ExecuteDbStatement($sql);
|
||||||
$this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
|
$this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
|
||||||
}
|
}
|
||||||
|
catch (Exception $ex)
|
||||||
|
{
|
||||||
|
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->getDatabaseService()->GetDbConnectionRaw()->commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user