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

fixed bug on schema comparator, prevent multiple rename candidates for a single original field #213

Merged
merged 7 commits into from May 1, 2013
8 changes: 5 additions & 3 deletions lib/Doctrine/DBAL/Schema/Comparator.php
Expand Up @@ -283,9 +283,11 @@ private function detectColumnRenamings(TableDiff $tableDifferences)
$removedColumnName = strtolower($removedColumn->getName());
$addedColumnName = strtolower($addedColumn->getName());

$tableDifferences->renamedColumns[$removedColumnName] = $addedColumn;
unset($tableDifferences->addedColumns[$addedColumnName]);
unset($tableDifferences->removedColumns[$removedColumnName]);
if ( ! isset($tableDifferences->renamedColumns[$removedColumnName])) {
$tableDifferences->renamedColumns[$removedColumnName] = $addedColumn;
unset($tableDifferences->addedColumns[$addedColumnName]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing line break

unset($tableDifferences->removedColumns[$removedColumnName]);
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
Expand Up @@ -210,6 +210,26 @@ public function testCompareChangedColumns_ChangeCustomSchemaOption()
$this->assertEquals(array(), $c->diffColumn($column1, $column1));
}

public function testCompareChangeColumns_MultipleNewColumnsRename()
{
$tableA = new Table("foo");
$tableA->addColumn('datefield1', 'datetime');

$tableB = new Table("foo");
$tableB->addColumn('new_datefield1', 'datetime');
$tableB->addColumn('new_datefield2', 'datetime');

$c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB);

$this->assertCount(1, $tableDiff->renamedColumns, "we should have one rename datefield1 => new_datefield1.");
$this->assertArrayHasKey('datefield1', $tableDiff->renamedColumns, "'datefield1' should be set to be renamed to new_datefield1");
$this->assertCount(1, $tableDiff->addedColumns, "'new_datefield2' should be added");
$this->assertArrayHasKey('new_datefield2', $tableDiff->addedColumns, "'new_datefield2' should be added, not created through renaming!");
$this->assertCount(0, $tableDiff->removedColumns, "Nothing should be removed.");
$this->assertCount(0, $tableDiff->changedColumns, "Nothing should be changed as all fields old & new have diff names.");
}

public function testCompareRemovedIndex()
{
$schema1 = new Schema( array(
Expand Down