Commit 2c1f6d71 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-586'

parents 99180ebf 894493b2
......@@ -572,6 +572,12 @@ class MySqlPlatform extends AbstractPlatform
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
}
if (isset($diff->addedIndexes['primary'])) {
$keyColumns = array_unique(array_values($diff->addedIndexes['primary']->getColumns()));
$queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')';
unset($diff->addedIndexes['primary']);
}
$sql = array();
$tableSql = array();
......
......@@ -314,7 +314,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$diffTable->setPrimaryKey(array('id'));
$this->assertEquals(
array('ALTER TABLE alter_table_add_pk DROP INDEX idx_id, ADD PRIMARY KEY (id)'),
array('DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'),
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
);
}
......@@ -343,4 +343,40 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
);
}
/**
* @group DBAL-586
*/
public function testAddAutoIncrementPrimaryKey()
{
$keyTable = new Table("foo");
$keyTable->addColumn("id", "integer", array('autoincrement' => true));
$keyTable->addColumn("baz", "string");
$keyTable->setPrimaryKey(array("id"));
$oldTable = new Table("foo");
$oldTable->addColumn("baz", "string");
$c = new \Doctrine\DBAL\Schema\Comparator;
$diff = $c->diffTable($oldTable, $keyTable);
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array(
"ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)",
), $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(
"ALTER TABLE mytable DROP PRIMARY KEY",
"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