diff --git a/lib/Doctrine/Migrations/Tracking/TableManipulator.php b/lib/Doctrine/Migrations/Tracking/TableManipulator.php index 6dbbde1e8c..e94327e5f4 100644 --- a/lib/Doctrine/Migrations/Tracking/TableManipulator.php +++ b/lib/Doctrine/Migrations/Tracking/TableManipulator.php @@ -53,15 +53,7 @@ public function createMigrationTable() : bool } if ($this->migrationTableStatus->isCreated()) { - if (! $this->migrationTableStatus->isUpToDate()) { - $this->migrationTableUpdater->updateMigrationTable(); - - $this->migrationTableStatus->setUpToDate(true); - - return true; - } - - return false; + return $this->migrationTableUpdater->updateMigrationTable(); } $table = $this->migrationTable->getNewDBALTable(); diff --git a/lib/Doctrine/Migrations/Tracking/TableStatus.php b/lib/Doctrine/Migrations/Tracking/TableStatus.php index a3b781de4f..b84481b2f6 100644 --- a/lib/Doctrine/Migrations/Tracking/TableStatus.php +++ b/lib/Doctrine/Migrations/Tracking/TableStatus.php @@ -22,9 +22,6 @@ class TableStatus /** @var bool|null */ private $created; - /** @var bool|null */ - private $upToDate; - public function __construct( AbstractSchemaManager $schemaManager, TableDefinition $migrationTable @@ -48,31 +45,4 @@ public function isCreated() : bool return $this->created; } - - public function setUpToDate(bool $upToDate) : void - { - $this->upToDate = $upToDate; - } - - public function isUpToDate() : bool - { - if ($this->upToDate !== null) { - return $this->upToDate; - } - - $table = $this->schemaManager->listTableDetails($this->migrationTable->getName()); - - $this->upToDate = true; - - foreach ($this->migrationTable->getColumnNames() as $columnName) { - if ($table->hasColumn($columnName)) { - continue; - } - - $this->upToDate = false; - break; - } - - return $this->upToDate; - } } diff --git a/lib/Doctrine/Migrations/Tracking/TableUpdater.php b/lib/Doctrine/Migrations/Tracking/TableUpdater.php index 66693acdf2..18a397649b 100644 --- a/lib/Doctrine/Migrations/Tracking/TableUpdater.php +++ b/lib/Doctrine/Migrations/Tracking/TableUpdater.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; use Throwable; +use function count; use function in_array; /** @@ -43,7 +44,7 @@ public function __construct( $this->platform = $platform; } - public function updateMigrationTable() : void + public function updateMigrationTable() : bool { $fromTable = $this->getFromTable(); $toTable = $this->migrationTable->getDBALTable(); @@ -66,6 +67,8 @@ public function updateMigrationTable() : void } $this->connection->commit(); + + return count($queries) !== 0; } /** diff --git a/tests/Doctrine/Migrations/Tests/Functional/MigrationTableManipulatorTest.php b/tests/Doctrine/Migrations/Tests/Functional/MigrationTableManipulatorTest.php index 118eab593a..71f2b642a6 100644 --- a/tests/Doctrine/Migrations/Tests/Functional/MigrationTableManipulatorTest.php +++ b/tests/Doctrine/Migrations/Tests/Functional/MigrationTableManipulatorTest.php @@ -31,7 +31,6 @@ public function testCreateMigrationTable() : void self::assertTrue($schemaManager->tablesExist(['doctrine_migration_versions'])); self::assertTrue($this->trackingTableStatus->isCreated()); - self::assertTrue($this->trackingTableStatus->isUpToDate()); $table = $schemaManager->listTableDetails('doctrine_migration_versions'); @@ -58,12 +57,9 @@ public function testUpdateMigrationTable() : void } self::assertTrue($this->trackingTableStatus->isCreated()); - self::assertFalse($this->trackingTableStatus->isUpToDate()); self::assertTrue($this->trackingTableManipulator->createMigrationTable()); - self::assertTrue($this->trackingTableStatus->isUpToDate()); - $schemaManager = $this->connection->getSchemaManager(); $table = $schemaManager->listTableDetails('doctrine_migration_versions'); diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php index 95971e75de..10b5e81a64 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php @@ -47,10 +47,6 @@ public function testCreateMigrationTableAlreadyCreated() : void ->method('isCreated') ->willReturn(true); - $this->migrationTableStatus->expects(self::once()) - ->method('isUpToDate') - ->willReturn(true); - self::assertFalse($this->migrationTableManipulator->createMigrationTable()); } @@ -78,16 +74,9 @@ public function testCreateMigrationTableNotUpToDate() : void ->method('isCreated') ->willReturn(true); - $this->migrationTableStatus->expects(self::once()) - ->method('isUpToDate') - ->willReturn(false); - $this->migrationTableUpdater->expects(self::once()) - ->method('updateMigrationTable'); - - $this->migrationTableStatus->expects(self::once()) - ->method('setUpToDate') - ->with(true); + ->method('updateMigrationTable') + ->willReturn(true); self::assertTrue($migrationTableManipulator->createMigrationTable()); } diff --git a/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php b/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php index 67d393d92c..637650f8dd 100644 --- a/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php +++ b/tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php @@ -5,7 +5,6 @@ namespace Doctrine\Migrations\Tests\Tracking; use Doctrine\DBAL\Schema\AbstractSchemaManager; -use Doctrine\DBAL\Schema\Table; use Doctrine\Migrations\Tracking\TableDefinition; use Doctrine\Migrations\Tracking\TableStatus; use PHPUnit\Framework\MockObject\MockObject; @@ -57,79 +56,6 @@ public function testIsCreatedFalse() : void self::assertFalse($this->migrationTableStatus->isCreated()); } - public function testSetUpToDate() : void - { - $this->migrationTableStatus->setUpToDate(true); - - self::assertTrue($this->migrationTableStatus->isUpToDate()); - } - - public function testIsUpToDateTrue() : void - { - $this->migrationTable->expects(self::once()) - ->method('getName') - ->willReturn('table_name'); - - $table = $this->createMock(Table::class); - - $this->schemaManager->expects(self::once()) - ->method('listTableDetails') - ->with('table_name') - ->willReturn($table); - - $this->migrationTable->expects(self::once()) - ->method('getColumnNames') - ->willReturn([ - 'version', - 'executed_at', - ]); - - $table->expects(self::at(0)) - ->method('hasColumn') - ->with('version') - ->willReturn(true); - - $table->expects(self::at(1)) - ->method('hasColumn') - ->with('executed_at') - ->willReturn(true); - - self::assertTrue($this->migrationTableStatus->isUpToDate()); - } - - public function testIsUpToDateFalse() : void - { - $this->migrationTable->expects(self::once()) - ->method('getName') - ->willReturn('table_name'); - - $table = $this->createMock(Table::class); - - $this->schemaManager->expects(self::once()) - ->method('listTableDetails') - ->with('table_name') - ->willReturn($table); - - $this->migrationTable->expects(self::once()) - ->method('getColumnNames') - ->willReturn([ - 'version', - 'executed_at', - ]); - - $table->expects(self::at(0)) - ->method('hasColumn') - ->with('version') - ->willReturn(true); - - $table->expects(self::at(1)) - ->method('hasColumn') - ->with('executed_at') - ->willReturn(false); - - self::assertFalse($this->migrationTableStatus->isUpToDate()); - } - protected function setUp() : void { $this->schemaManager = $this->createMock(AbstractSchemaManager::class);