Skip to content

Commit

Permalink
Add compatibility with mariadb
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Devlamynck committed May 16, 2024
1 parent aba3f7e commit 6c95e0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Doctrine/DatabaseSchemaInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions Doctrine/Driver/StaticDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 6c95e0d

Please sign in to comment.