Skip to content

Commit

Permalink
[DBAL-591] Fix issue with drop constraint + column ordering in ALTER …
Browse files Browse the repository at this point in the history
…TABLE of PostgreSQL.
  • Loading branch information
beberlei committed Dec 21, 2013
1 parent 4e024dc commit e1cd82a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public function getAlterTableSQL(TableDiff $diff)
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}

$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
$sql = array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $sql, $this->getPostAlterTableIndexForeignKeySQL($diff), $commentsSQL);
}

return array_merge($sql, $tableSql, $columnSql);
Expand Down
27 changes: 27 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,32 @@ public function testAlterDecimalPrecisionScale()

$this->assertEquals($expectedSql, $sql);
}

/**
* @group DBAL-365
*/
public function testDroppingConstraintsBeforeColumns()
{
$newTable = new Table('mytable');
$newTable->addColumn('id', 'integer');
$newTable->setPrimaryKey(array('id'));

$oldTable = clone $newTable;
$oldTable->addColumn('parent_id', 'integer');
$oldTable->addUnnamedForeignKeyConstraint('mytable', array('parent_id'), array('id'));

$comparator = new \Doctrine\DBAL\Schema\Comparator();
$tableDiff = $comparator->diffTable($oldTable, $newTable);

$sql = $this->_platform->getAlterTableSQL($tableDiff);

$expectedSql = array(
'ALTER TABLE mytable DROP CONSTRAINT FK_6B2BD609727ACA70',
'DROP INDEX IDX_6B2BD609727ACA70',
'ALTER TABLE mytable DROP parent_id',
);

$this->assertEquals($expectedSql, $sql);
}
}

0 comments on commit e1cd82a

Please sign in to comment.