Commit 8f94c5dc authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-591'

parents feedcfae efaff48b
...@@ -508,7 +508,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -508,7 +508,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName; $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); return array_merge($sql, $tableSql, $columnSql);
......
...@@ -336,19 +336,18 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase ...@@ -336,19 +336,18 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
} }
public function testAlterDecimalPrecisionScale() public function testAlterDecimalPrecisionScale()
{ {
$table = new Table('mytable'); $table = new Table('mytable');
$table->addColumn('dfoo1', 'decimal'); $table->addColumn('dfoo1', 'decimal');
$table->addColumn('dfoo2', 'decimal', array('precision' => 10, 'scale' => 6)); $table->addColumn('dfoo2', 'decimal', array('precision' => 10, 'scale' => 6));
$table->addColumn('dfoo3', 'decimal', array('precision' => 10, 'scale' => 6)); $table->addColumn('dfoo3', 'decimal', array('precision' => 10, 'scale' => 6));
$table->addColumn('dfoo4', 'decimal', array('precision' => 10, 'scale' => 6)); $table->addColumn('dfoo4', 'decimal', array('precision' => 10, 'scale' => 6));
$tableDiff = new TableDiff('mytable'); $tableDiff = new TableDiff('mytable');
$tableDiff->fromTable = $table; $tableDiff->fromTable = $table;
$tableDiff->changedColumns['dloo1'] = new \Doctrine\DBAL\Schema\ColumnDiff( $tableDiff->changedColumns['dloo1'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'dloo1', new \Doctrine\DBAL\Schema\Column( 'dloo1', new \Doctrine\DBAL\Schema\Column(
'dloo1', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 16, 'scale' => 6) 'dloo1', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 16, 'scale' => 6)
...@@ -373,9 +372,9 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase ...@@ -373,9 +372,9 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
), ),
array('precision', 'scale') array('precision', 'scale')
); );
$sql = $this->_platform->getAlterTableSQL($tableDiff); $sql = $this->_platform->getAlterTableSQL($tableDiff);
$expectedSql = array( $expectedSql = array(
'ALTER TABLE mytable ALTER dloo1 TYPE NUMERIC(16, 6)', 'ALTER TABLE mytable ALTER dloo1 TYPE NUMERIC(16, 6)',
'ALTER TABLE mytable ALTER dloo2 TYPE NUMERIC(10, 4)', 'ALTER TABLE mytable ALTER dloo2 TYPE NUMERIC(10, 4)',
...@@ -384,4 +383,31 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase ...@@ -384,4 +383,31 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
$this->assertEquals($expectedSql, $sql); $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);
}
} }
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