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..8c08c2a 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 static 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(); } }