Use transactions for database migrations

This commit is contained in:
Bernd Bestel 2020-11-17 20:22:38 +01:00
parent 6270f39688
commit 5634abed82
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300

View File

@ -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();
}
}
}