Commit fa2a12e7 authored by Immanuel Klinkenberg's avatar Immanuel Klinkenberg

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

primary key on MySQL platform.
parent e0169b2a
......@@ -708,6 +708,10 @@ class MySqlPlatform extends AbstractPlatform
// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
foreach ($index->getColumns() as $columnName) {
if (! $diff->fromTable->hasColumn($columnName)) {
continue;
}
$column = $diff->fromTable->getColumn($columnName);
if ($column->getAutoincrement() === true) {
......
......@@ -473,6 +473,30 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
"ALTER TABLE mytable ADD PRIMARY KEY (foo)",
), $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()
{
......
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