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

calculate diff correctly to verify up-to-date status #970

Open
wants to merge 5 commits into
base: 2.3.x
Choose a base branch
from
Open
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
10 changes: 1 addition & 9 deletions lib/Doctrine/Migrations/Tracking/TableManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 0 additions & 30 deletions lib/Doctrine/Migrations/Tracking/TableStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class TableStatus
/** @var bool|null */
private $created;

/** @var bool|null */
private $upToDate;

public function __construct(
AbstractSchemaManager $schemaManager,
TableDefinition $migrationTable
Expand All @@ -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;
}
}
5 changes: 4 additions & 1 deletion lib/Doctrine/Migrations/Tracking/TableUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Throwable;
use function count;
use function in_array;

/**
Expand Down Expand Up @@ -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();
Expand All @@ -66,6 +67,8 @@ public function updateMigrationTable() : void
}

$this->connection->commit();

return count($queries) !== 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');
Expand Down
15 changes: 2 additions & 13 deletions tests/Doctrine/Migrations/Tests/Tracking/TableManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
}
Expand Down
74 changes: 0 additions & 74 deletions tests/Doctrine/Migrations/Tests/Tracking/TableStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down