Commit f5f99cd4 authored by Steve Müller's avatar Steve Müller

Merge pull request #861 from mpoiriert/patch-1

Check for foreign table name on removed tables foreign key

fixes #1185
parents 50f4482f 0de5c7aa
......@@ -116,6 +116,10 @@ class Comparator
$localTableName = strtolower($foreignKey->getLocalTableName());
if (isset($diff->changedTables[$localTableName])) {
foreach ($diff->changedTables[$localTableName]->removedForeignKeys as $key => $removedForeignKey) {
// We check if the key is from the removed table if not we skip.
if ($tableName !== strtolower($removedForeignKey->getForeignTableName())) {
continue;
}
unset($diff->changedTables[$localTableName]->removedForeignKeys[$key]);
}
}
......
......@@ -978,22 +978,33 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
{
$oldSchema = new Schema();
$tableForeign = $oldSchema->createTable('foreign');
$tableForeign->addColumn('id', 'integer');
$tableA = $oldSchema->createTable('table_a');
$tableA->addColumn('id', 'integer');
$tableB = $oldSchema->createTable('table_b');
$tableB->addColumn('id', 'integer');
$table = $oldSchema->createTable('foo');
$table->addColumn('fk', 'integer');
$table->addForeignKeyConstraint($tableForeign, array('fk'), array('id'));
$tableC = $oldSchema->createTable('table_c');
$tableC->addColumn('id', 'integer');
$tableC->addColumn('table_a_id', 'integer');
$tableC->addColumn('table_b_id', 'integer');
$tableC->addForeignKeyConstraint($tableA, array('table_a_id'), array('id'));
$tableC->addForeignKeyConstraint($tableB, array('table_b_id'), array('id'));
$newSchema = new Schema();
$table = $newSchema->createTable('foo');
$c = new Comparator();
$diff = $c->compare($oldSchema, $newSchema);
$tableB = $newSchema->createTable('table_b');
$tableB->addColumn('id', 'integer');
$tableC = $newSchema->createTable('table_c');
$tableC->addColumn('id', 'integer');
$comparator = new Comparator();
$schemaDiff = $comparator->compare($oldSchema, $newSchema);
$this->assertCount(0, $diff->changedTables['foo']->removedForeignKeys);
$this->assertCount(1, $diff->orphanedForeignKeys);
$this->assertCount(1, $schemaDiff->changedTables['table_c']->removedForeignKeys);
$this->assertCount(1, $schemaDiff->orphanedForeignKeys);
}
public function testCompareChangedColumn()
......
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