Commit c41cc5a6 authored by Immanuel Klinkenberg's avatar Immanuel Klinkenberg Committed by Steve Müller

Fix primary key alteration when adding new columns to a table and it's

primary key on MySQL platform.
parent 3cc78d64
...@@ -699,6 +699,10 @@ class MySqlPlatform extends AbstractPlatform ...@@ -699,6 +699,10 @@ class MySqlPlatform extends AbstractPlatform
// Dropping primary keys requires to unset autoincrement attribute on the particular column first. // Dropping primary keys requires to unset autoincrement attribute on the particular column first.
foreach ($index->getColumns() as $columnName) { foreach ($index->getColumns() as $columnName) {
if (! $diff->fromTable->hasColumn($columnName)) {
continue;
}
$column = $diff->fromTable->getColumn($columnName); $column = $diff->fromTable->getColumn($columnName);
if ($column->getAutoincrement() === true) { if ($column->getAutoincrement() === true) {
......
...@@ -473,6 +473,30 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -473,6 +473,30 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
"ALTER TABLE mytable ADD PRIMARY KEY (foo)", "ALTER TABLE mytable ADD PRIMARY KEY (foo)",
), $sql); ), $sql);
} }
public function testAlterPrimaryKeyWithNewColumn()
{
$table = new Table("yolo");
$table->addColumn('pkc1', 'integer');
$table->addColumn('col_a', 'integer');
$table->setPrimaryKey(array('pkc1'));
$comparator = new Comparator();
$diffTable = clone $table;
$diffTable->addColumn('pkc2', 'integer');
$diffTable->dropPrimaryKey();
$diffTable->setPrimaryKey(array('pkc1', 'pkc2'));
$this->assertSame(
array(
'ALTER TABLE yolo DROP PRIMARY KEY',
'ALTER TABLE yolo ADD pkc2 INT NOT NULL',
'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)',
),
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
);
}
public function testInitializesDoctrineTypeMappings() public function testInitializesDoctrineTypeMappings()
{ {
......
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