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

Merge 2.3.x into master #920

Merged
merged 8 commits into from
Jan 18, 2020
2 changes: 1 addition & 1 deletion docs/en/reference/managing-migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions lib/Doctrine/Migrations/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 Psr\Log\LoggerInterface;
use function func_get_args;
Expand Down Expand Up @@ -93,24 +95,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;

/**
Expand Down Expand Up @@ -138,6 +158,9 @@ protected function write(string $message) : void
$this->logger->notice($message, ['migration' => $this]);
}

/**
* @throws IrreversibleMigration
*/
protected function throwIrreversibleMigrationException(?string $message = null) : void
{
if ($message === null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/Migrations/Version/DbalExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ private function executeResult(MigratorConfiguration $configuration) : void
$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();
Expand Down
20 changes: 20 additions & 0 deletions tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ public function testExecuteUp() : void
], $this->logger->logs);
}

public function testExecuteUsedExecuteUpdate() : void
{
$this->connection
->expects(self::never())
->method('executeQuery');
$this->connection
->expects(self::exactly(2))
->method('executeUpdate');

$plan = new MigrationPlan($this->version, $this->migration, Direction::UP);

$migratorConfiguration = (new MigratorConfiguration())
->setTimeAllQueries(true);

$this->versionExecutor->execute(
$plan,
$migratorConfiguration
);
}

/**
* @test
*/
Expand Down