Permalink
Browse files

Fixed diff generator when several identical columns were renamed

Fixed diff generator when two tables have several columns with
identical DDL and several of them were renamed.
  • Loading branch information...
1 parent af52773 commit f62d33455e6c120930ef4d7331182f45017ac81e @javer javer committed Mar 4, 2014
@@ -153,6 +153,8 @@ public function compareColumns($caseInsensitive = false)
$this->tableDiff->removeAddedColumn($addedColumnName);
$this->tableDiff->removeRemovedColumn($removedColumnName);
$columnDifferences--;
+ // skip to the next added column
+ continue 2;
}
}
}
@@ -201,6 +203,8 @@ public function comparePrimaryKeys($caseInsensitive = false)
$this->tableDiff->removeAddedPkColumn($addedColumnName);
$this->tableDiff->removeRemovedPkColumn($removedColumnName);
$pkDifferences--;
+ // skip to the next added column
+ continue 2;
}
}
}
@@ -226,4 +226,47 @@ public function testCompareSeveralColumnDifferences()
$this->assertEquals(array('col1' => $columnDiff), $tableDiff->getModifiedColumns());
}
+ public function testCompareSeveralRenamedSameColumns()
+ {
+ $t1 = new Table();
+ $c1 = new Column('col1');
+ $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
+ $c1->getDomain()->replaceSize(255);
+ $t1->addColumn($c1);
+ $c2 = new Column('col2');
+ $c2->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
+ $c2->getDomain()->replaceSize(255);
+ $t1->addColumn($c2);
+ $c3 = new Column('col3');
+ $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
+ $c3->getDomain()->replaceSize(255);
+ $t1->addColumn($c3);
+
+ $t2 = new Table();
+ $c4 = new Column('col4');
+ $c4->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
+ $c4->getDomain()->replaceSize(255);
+ $t2->addColumn($c4);
+ $c5 = new Column('col5');
+ $c5->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
+ $c5->getDomain()->replaceSize(255);
+ $t2->addColumn($c5);
+ $c6 = new Column('col3');
+ $c6->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
+ $c6->getDomain()->replaceSize(255);
+ $t2->addColumn($c6);
+
+ // col1 and col2 were renamed
+ $tc = new PropelTableComparator();
+ $tc->setFromTable($t1);
+ $tc->setToTable($t2);
+ $nbDiffs = $tc->compareColumns();
+ $tableDiff = $tc->getTableDiff();
+ $this->assertEquals(2, $nbDiffs);
+ $this->assertEquals(array(array($c1, $c4), array($c2, $c5)), $tableDiff->getRenamedColumns());
+ $this->assertEquals(array(), $tableDiff->getAddedColumns());
+ $this->assertEquals(array(), $tableDiff->getRemovedColumns());
+ $this->assertEquals(array(), $tableDiff->getModifiedColumns());
+ }
+
}
@@ -183,4 +183,52 @@ public function testCompareSeveralPrimaryKeyDifferences()
$this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedPkColumns());
}
+ public function testCompareSeveralRenamedSamePrimaryKeys()
+ {
+ $t1 = new Table();
+ $c1 = new Column('col1');
+ $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $c1->setNotNull(true);
+ $c1->setPrimaryKey(true);
+ $t1->addColumn($c1);
+ $c2 = new Column('col2');
+ $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $c2->setNotNull(true);
+ $c2->setPrimaryKey(true);
+ $t1->addColumn($c2);
+ $c3 = new Column('col3');
+ $c3->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $c3->setNotNull(true);
+ $c3->setPrimaryKey(true);
+ $t1->addColumn($c3);
+
+ $t2 = new Table();
+ $c4 = new Column('col4');
+ $c4->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $c4->setNotNull(true);
+ $c4->setPrimaryKey(true);
+ $t2->addColumn($c4);
+ $c5 = new Column('col5');
+ $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $c5->setNotNull(true);
+ $c5->setPrimaryKey(true);
+ $t2->addColumn($c5);
+ $c6 = new Column('col3');
+ $c6->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $c6->setNotNull(true);
+ $c6->setPrimaryKey(true);
+ $t2->addColumn($c6);
+
+ // col1 and col2 were renamed
+ $tc = new PropelTableComparator();
+ $tc->setFromTable($t1);
+ $tc->setToTable($t2);
+ $nbDiffs = $tc->comparePrimaryKeys();
+ $tableDiff = $tc->getTableDiff();
+ $this->assertEquals(2, $nbDiffs);
+ $this->assertEquals(array(array($c1, $c4), array($c2, $c5)), $tableDiff->getRenamedPkColumns());
+ $this->assertEquals(array(), $tableDiff->getAddedPkColumns());
+ $this->assertEquals(array(), $tableDiff->getRemovedPkColumns());
+ }
+
}

0 comments on commit f62d334

Please sign in to comment.