Permalink
Browse files

Merge pull request #839 from javer/patch-diff-samecolumns

Fixed diff generator when several identical tables or columns were renamed
  • Loading branch information...
2 parents 3f5e010 + b313c3d commit 10fe1be60e6facab893d04aa2b37a0034d581309 @willdurand willdurand committed Mar 16, 2014
@@ -149,6 +149,8 @@ public function compareTables($caseInsensitive = false)
$this->databaseDiff->removeAddedTable($addedTableName);
$this->databaseDiff->removeRemovedTable($removedTableName);
$databaseDifferences--;
+ // skip to the next added table
+ break;
}
}
}
@@ -153,6 +153,8 @@ public function compareColumns($caseInsensitive = false)
$this->tableDiff->removeAddedColumn($addedColumnName);
$this->tableDiff->removeRemovedColumn($removedColumnName);
$columnDifferences--;
+ // skip to the next added column
+ break;
}
}
}
@@ -201,6 +203,8 @@ public function comparePrimaryKeys($caseInsensitive = false)
$this->tableDiff->removeAddedPkColumn($addedColumnName);
$this->tableDiff->removeRemovedPkColumn($removedColumnName);
$pkDifferences--;
+ // skip to the next added column
+ break;
}
}
}
@@ -399,4 +399,52 @@ public function testCompareSeveralTableDifferences()
$this->assertEquals(array('Foo_Table' => $tableDiff), $databaseDiff->getModifiedTables());
}
+ public function testCompareSeveralRenamedSameTables()
+ {
+ $d1 = new Database();
+ $t1 = new Table('table1');
+ $c1 = new Column('col1');
+ $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $t1->addColumn($c1);
+ $d1->addTable($t1);
+ $t2 = new Table('table2');
+ $c2 = new Column('col1');
+ $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $t2->addColumn($c2);
+ $d1->addTable($t2);
+ $t3 = new Table('table3');
+ $c3 = new Column('col1');
+ $c3->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $t3->addColumn($c3);
+ $d1->addTable($t3);
+
+ $d2 = new Database();
+ $t4 = new Table('table4');
+ $c4 = new Column('col1');
+ $c4->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $t4->addColumn($c4);
+ $d2->addTable($t4);
+ $t5 = new Table('table5');
+ $c5 = new Column('col1');
+ $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $t5->addColumn($c5);
+ $d2->addTable($t5);
+ $t6 = new Table('table3');
+ $c6 = new Column('col1');
+ $c6->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
+ $t6->addColumn($c6);
+ $d2->addTable($t6);
+
+ $dc = new PropelDatabaseComparator();
+ $dc->setFromDatabase($d1);
+ $dc->setToDatabase($d2);
+ $nbDiffs = $dc->compareTables();
+ $databaseDiff = $dc->getDatabaseDiff();
+ $this->assertEquals(2, $nbDiffs);
+ $this->assertEquals(2, count($databaseDiff->getRenamedTables()));
+ $this->assertEquals(array('table1' => 'table4', 'table2' => 'table5'), $databaseDiff->getRenamedTables());
+ $this->assertEquals(array(), $databaseDiff->getAddedTables());
+ $this->assertEquals(array(), $databaseDiff->getRemovedTables());
+ }
+
}
@@ -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 10fe1be

Please sign in to comment.