From e19a496f79bbc9e69117bc383f4fa692deb48fd1 Mon Sep 17 00:00:00 2001 From: Matthias Devlamynck Date: Thu, 16 May 2024 16:59:20 +0200 Subject: [PATCH] Add compatibility with mariadb --- Doctrine/DatabaseSchemaInitializer.php | 8 ++++---- Doctrine/Driver/StaticDriver.php | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Doctrine/DatabaseSchemaInitializer.php b/Doctrine/DatabaseSchemaInitializer.php index 32906f9..07cc5a5 100644 --- a/Doctrine/DatabaseSchemaInitializer.php +++ b/Doctrine/DatabaseSchemaInitializer.php @@ -26,10 +26,10 @@ public static function init(EntityManagerInterface $entityManager): void $metadatas = $entityManager->getMetadataFactory()->getAllMetadata(); $schemaTool = new SchemaTool($entityManager); - StaticDriver::withoutTransaction(static function () use ($schemaTool, $metadatas) { - $schemaTool->dropDatabase(); - $schemaTool->createSchema($metadatas); - }); + + $schemaTool->dropDatabase(); + $schemaTool->createSchema($metadatas); + StaticDriver::forceCommit(); $key = self::getKey($entityManager); self::$initializedEntityManagers[$key] = true; diff --git a/Doctrine/Driver/StaticDriver.php b/Doctrine/Driver/StaticDriver.php index 90a1c34..50f681a 100644 --- a/Doctrine/Driver/StaticDriver.php +++ b/Doctrine/Driver/StaticDriver.php @@ -29,27 +29,25 @@ public static function beginTransaction(): void public static function rollBack(): void { - parent::rollBack(); static::$isInTransaction = false; + parent::rollBack(); } public static function commit(): void { - parent::commit(); static::$isInTransaction = false; + parent::commit(); } - public static function withoutTransaction(callable $callback): void + public function forceCommit(): void { - $callback(); - if (static::isInTransaction()) { try { static::commit(); - static::beginTransaction(); } catch (\Throwable $e) { - // Skip + // Ignore error because transaction could be already implicitly commited in case of schema changes } + static::beginTransaction(); } }