Skip to content

Commit

Permalink
[DBAL-586] Fix failures introduced by PR and adjust code.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Dec 20, 2013
1 parent fd28878 commit aedfbf2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
9 changes: 0 additions & 9 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Expand Up @@ -623,15 +623,6 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
}
}
}
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));

Expand Down
24 changes: 23 additions & 1 deletion tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
Expand Up @@ -296,6 +296,28 @@ public function testBlobTypeDeclarationSQL()
$this->assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array()));
}

/**
* @group DBAL-400
*/
public function testAlterTableAddPrimaryKey()
{
$table = new Table('alter_table_add_pk');
$table->addColumn('id', 'integer');
$table->addColumn('foo', 'integer');
$table->addIndex(array('id'), 'idx_id');

$comparator = new Comparator();
$diffTable = clone $table;

$diffTable->dropIndex('idx_id');
$diffTable->setPrimaryKey(array('id'));

$this->assertEquals(
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))
);
}

/**
* @group DBAL-464
*/
Expand Down Expand Up @@ -352,7 +374,7 @@ public function testNamedPrimaryKey()
$sql = $this->_platform->getAlterTableSQL($diff);

$this->assertEquals(array(
"DROP INDEX foo_index ON mytable",
"ALTER TABLE mytable DROP PRIMARY KEY",
"ALTER TABLE mytable ADD PRIMARY KEY (foo)",
), $sql);
}
Expand Down

0 comments on commit aedfbf2

Please sign in to comment.