Commit fd288786 authored by Bart Visscher's avatar Bart Visscher Committed by Benjamin Eberlei

When changing from a non-primary index to a primary index, the dropped index isn't named PRIMARY

parent bfa1e77b
...@@ -623,6 +623,15 @@ class MySqlPlatform extends AbstractPlatform ...@@ -623,6 +623,15 @@ class MySqlPlatform extends AbstractPlatform
} }
} }
} }
foreach ($diff->changedIndexes as $changedKey => $changedIndex) {
if ($changedIndex->isPrimary() && $changedKey != 'PRIMARY') {
$index = $diff->changedIndexes[$changedKey];
$index = new Index($changedKey, $index->getColumns(), $index->isUnique(), false);
$diff->removedIndexes[$changedKey] = $index;
$diff->addedIndexes['PRIMARY'] = $diff->changedIndexes[$changedKey];
unset($diff->changedIndexes[$changedKey]);
}
}
$sql = array_merge($sql, parent::getPreAlterTableIndexForeignKeySQL($diff)); $sql = array_merge($sql, parent::getPreAlterTableIndexForeignKeySQL($diff));
......
...@@ -343,4 +343,17 @@ class MySqlPlatformTest extends AbstractPlatformTestCase ...@@ -343,4 +343,17 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
"ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)", "ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)",
), $sql); ), $sql);
} }
public function testNamedPrimaryKey()
{
$diff = new TableDiff('mytable');
$diff->changedIndexes['foo_index'] = new Index('foo_index', array('foo'), true, true);
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array(
"DROP INDEX foo_index ON mytable",
"ALTER TABLE mytable ADD PRIMARY KEY (foo)",
), $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