Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use by default transactional DDL when the database engine does not support them #1152

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Doctrine/Migrations/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\Exception\AbortMigration;
Expand Down Expand Up @@ -52,15 +54,15 @@ public function __construct(Version $version)
/**
* Indicates the transactional mode of this migration.
*
* If this function returns true (default) the migration will be executed
* If this function returns true (default when the underlying database supports transactional DDL) the migration will be executed
* in one transaction, otherwise non-transactional state will be used to
* execute each of the migration SQLs.
*
* Extending class should override this function to alter the return value.
*/
public function isTransactional(): bool
{
return true;
return ! ($this->platform instanceof MySqlPlatform || $this->platform instanceof OraclePlatform);
}

public function getDescription(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\Common\EventSubscriber;
use Doctrine\Migrations\Event\MigrationsEventArgs;
use Doctrine\Migrations\Events;
use Doctrine\Migrations\Tools\TransactionHelper;

/**
* Listens for `onMigrationsMigrated` and, if the connection has autocommit
Expand All @@ -25,7 +24,7 @@ public function onMigrationsMigrated(MigrationsEventArgs $args): void
return;
}

TransactionHelper::commitIfInTransaction($conn);
$conn->commit();
}

/** {@inheritdoc} */
Expand Down
5 changes: 2 additions & 3 deletions lib/Doctrine/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\Migrations\Exception\NoMigrationsToExecute;
use Doctrine\Migrations\Exception\UnknownMigrationVersion;
use Doctrine\Migrations\Tools\BytesFormatter;
use Doctrine\Migrations\Tools\TransactionHelper;
use Doctrine\Migrations\Version\Direction;
use Doctrine\Migrations\Version\Version;
use Symfony\Component\Stopwatch\StopwatchEvent;
Expand Down Expand Up @@ -196,14 +195,14 @@ private function executeMigration(
$this->configuration->dispatchMigrationEvent(Events::onMigrationsMigrated, $direction, $dryRun);
} catch (Throwable $e) {
if ($allOrNothing) {
TransactionHelper::rollbackIfInTransaction($connection);
$connection->rollBack();
}

throw $e;
}

if ($allOrNothing) {
TransactionHelper::commitIfInTransaction($connection);
$connection->commit();
}

return $sql;
Expand Down
41 changes: 0 additions & 41 deletions lib/Doctrine/Migrations/Tools/TransactionHelper.php

This file was deleted.

5 changes: 2 additions & 3 deletions lib/Doctrine/Migrations/Tracking/TableUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Migrations\Tools\TransactionHelper;
use Throwable;

use function in_array;
Expand Down Expand Up @@ -62,12 +61,12 @@ public function updateMigrationTable(): void
$this->connection->executeQuery($query);
}
} catch (Throwable $e) {
TransactionHelper::rollbackIfInTransaction($this->connection);
$this->connection->rollBack();

throw $e;
}

TransactionHelper::commitIfInTransaction($this->connection);
$this->connection->commit();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/Migrations/Version/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\Migrations\Provider\SchemaDiffProviderInterface;
use Doctrine\Migrations\Stopwatch;
use Doctrine\Migrations\Tools\BytesFormatter;
use Doctrine\Migrations\Tools\TransactionHelper;
use Throwable;

use function count;
Expand Down Expand Up @@ -258,7 +257,8 @@ private function executeMigration(
}

if ($migration->isTransactional()) {
TransactionHelper::commitIfInTransaction($this->connection);
//commit only if running in transactional mode
$this->connection->commit();
}

$version->setState(State::NONE);
Expand Down Expand Up @@ -298,7 +298,7 @@ private function skipMigration(
): void {
if ($migration->isTransactional()) {
//only rollback transaction if in transactional mode
TransactionHelper::rollbackIfInTransaction($this->connection);
$this->connection->rollBack();
}

if (! $migratorConfiguration->isDryRun()) {
Expand Down Expand Up @@ -331,7 +331,7 @@ private function migrationError(Throwable $e, Version $version, AbstractMigratio

if ($migration->isTransactional()) {
//only rollback transaction if in transactional mode
TransactionHelper::rollbackIfInTransaction($this->connection);
$this->connection->rollBack();
}

$version->setState(State::NONE);
Expand Down