Commit d0e60928 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #213 from leedavis81/fix-schema-comparitor

fixed bug on schema comparator, prevent multiple rename candidates for a single original field
parents 01896d90 dbb1124b
...@@ -298,12 +298,14 @@ class Comparator ...@@ -298,12 +298,14 @@ class Comparator
$removedColumnName = strtolower($removedColumn->getName()); $removedColumnName = strtolower($removedColumn->getName());
$addedColumnName = strtolower($addedColumn->getName()); $addedColumnName = strtolower($addedColumn->getName());
if ( ! isset($tableDifferences->renamedColumns[$removedColumnName])) {
$tableDifferences->renamedColumns[$removedColumnName] = $addedColumn; $tableDifferences->renamedColumns[$removedColumnName] = $addedColumn;
unset($tableDifferences->addedColumns[$addedColumnName]); unset($tableDifferences->addedColumns[$addedColumnName]);
unset($tableDifferences->removedColumns[$removedColumnName]); unset($tableDifferences->removedColumns[$removedColumnName]);
} }
} }
} }
}
/** /**
* @param ForeignKeyConstraint $key1 * @param ForeignKeyConstraint $key1
......
...@@ -223,6 +223,26 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase ...@@ -223,6 +223,26 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $c->diffColumn($column1, $column1)); $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() public function testCompareRemovedIndex()
{ {
$schema1 = new Schema( array( $schema1 = new Schema( array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment