mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Use transactions for database migrations
This commit is contained in:
parent
6270f39688
commit
5634abed82
@ -49,8 +49,20 @@ class DatabaseMigrationService extends BaseService
|
||||
|
||||
if (intval($rowCount) === 0)
|
||||
{
|
||||
$this->getDatabaseService()->ExecuteDbStatement($sql);
|
||||
$this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
|
||||
$this->getDatabaseService()->GetDbConnectionRaw()->beginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
$this->getDatabaseService()->ExecuteDbStatement($sql);
|
||||
$this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
|
||||
}
|
||||
catch (Exception $ex)
|
||||
{
|
||||
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
$this->getDatabaseService()->GetDbConnectionRaw()->commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user