From 3a248fa977c54f8f2f8ecb553f3d0c58cd69b491 Mon Sep 17 00:00:00 2001 From: Mathieu Martinet Date: Wed, 13 Nov 2019 11:52:17 +0100 Subject: [PATCH 1/3] Fixed typo in the "--no-interaction" argument --- docs/en/reference/managing-migrations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/managing-migrations.rst b/docs/en/reference/managing-migrations.rst index bcaecab21b..094cc4c279 100644 --- a/docs/en/reference/managing-migrations.rst +++ b/docs/en/reference/managing-migrations.rst @@ -152,7 +152,7 @@ You may want to just execute a single migration up or down. You can do this with No Interaction -------------- -Alternately, if you wish to run the migrations in an unattended mode, we can add the ``--no--interaction`` option and then +Alternately, if you wish to run the migrations in an unattended mode, we can add the ``--no-interaction`` option and then execute the migrations without any extra prompting from Doctrine. .. code-block:: sh From 87d43d21486010163c83e16663747424e73cc641 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 2 Dec 2019 16:46:16 +0100 Subject: [PATCH 2/3] Allow to throw Exception in Migrations --- lib/Doctrine/Migrations/AbstractMigration.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/Doctrine/Migrations/AbstractMigration.php b/lib/Doctrine/Migrations/AbstractMigration.php index a684780143..dcfa08c1f9 100644 --- a/lib/Doctrine/Migrations/AbstractMigration.php +++ b/lib/Doctrine/Migrations/AbstractMigration.php @@ -5,11 +5,13 @@ namespace Doctrine\Migrations; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\Exception\AbortMigration; use Doctrine\Migrations\Exception\IrreversibleMigration; +use Doctrine\Migrations\Exception\MigrationException; use Doctrine\Migrations\Exception\SkipMigration; use Doctrine\Migrations\Version\Version; use function sprintf; @@ -100,24 +102,42 @@ public function skipIf(bool $condition, string $message = '') : void } } + /** + * @throws MigrationException|DBALException + */ public function preUp(Schema $schema) : void { } + /** + * @throws MigrationException|DBALException + */ public function postUp(Schema $schema) : void { } + /** + * @throws MigrationException|DBALException + */ public function preDown(Schema $schema) : void { } + /** + * @throws MigrationException|DBALException + */ public function postDown(Schema $schema) : void { } + /** + * @throws MigrationException|DBALException + */ abstract public function up(Schema $schema) : void; + /** + * @throws MigrationException|DBALException + */ abstract public function down(Schema $schema) : void; /** @@ -137,6 +157,9 @@ protected function write(string $message) : void $this->outputWriter->write($message); } + /** + * @throws IrreversibleMigration + */ protected function throwIrreversibleMigrationException(?string $message = null) : void { if ($message === null) { From 595489b4c456a6926365e270cdaba8c401350506 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 5 Dec 2019 08:44:08 +0100 Subject: [PATCH 3/3] use executeUpdate for migration queries as it is a write operation --- lib/Doctrine/Migrations/Version/Executor.php | 4 ++-- .../Migrations/Tests/Version/ExecutorTest.php | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Migrations/Version/Executor.php b/lib/Doctrine/Migrations/Version/Executor.php index 76d2798e12..199d91bce4 100644 --- a/lib/Doctrine/Migrations/Version/Executor.php +++ b/lib/Doctrine/Migrations/Version/Executor.php @@ -344,9 +344,9 @@ private function executeVersionExecutionResult( $this->outputSqlQuery($key, $query); if (! isset($this->params[$key])) { - $this->connection->executeQuery($query); + $this->connection->executeUpdate($query); } else { - $this->connection->executeQuery($query, $this->params[$key], $this->types[$key]); + $this->connection->executeUpdate($query, $this->params[$key], $this->types[$key]); } $stopwatchEvent->stop(); diff --git a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php index de4fd93969..c138f5cdbe 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php @@ -107,6 +107,26 @@ public function testExecuteUp() : void self::assertFalse($this->migration->postDownExecuted); } + public function testExecuteUsedExecuteUpdate() : void + { + $this->connection + ->expects(self::never()) + ->method('executeQuery'); + $this->connection + ->expects(self::exactly(2)) + ->method('executeUpdate'); + + $migratorConfiguration = (new MigratorConfiguration()) + ->setTimeAllQueries(true); + + $this->versionExecutor->execute( + $this->version, + $this->migration, + Direction::UP, + $migratorConfiguration + ); + } + /** * @test */