Skip to content

Commit

Permalink
Fixes of primary key management for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
SCIF committed Mar 29, 2018
1 parent c7a088b commit 2e29acd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,11 @@ public function getAlterTableSQL(TableDiff $diff)
$oldColumnName = new Identifier($oldColumnName);
$columnArray = $column->toArray();
$columnArray['comment'] = $this->getColumnComment($column);

if ($column->getAutoincrement()) {
$queryParts[] = 'ADD INDEX (' . $column->getName() . ')';
}

$queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1400,14 +1400,14 @@ public function testCreateAndListSequences() : void
*/
public function testAlterTableChangePrimaryKey() : void
{
$tableFrom = new Table('primary_key_userid');
$tableFrom = new Table('primary_key_id');
$column = $tableFrom->addColumn('user_id', 'integer');
$column->setAutoincrement(true);
$tableFrom->setPrimaryKey(['user_id']);
$this->_sm->dropAndCreateTable($tableFrom);

$tableFrom = $this->_sm->listTableDetails('primary_key_userid');
self::assertEquals(['user_id'], $tableFrom->getPrimaryKey()->getColumns());
$tableFrom = $this->_sm->listTableDetails('primary_key_id');
self::assertEquals(['USER_ID'], array_map('strtoupper', $tableFrom->getPrimaryKey()->getColumns()));

$tableTo = new Table('primary_key_id');
$column = $tableTo->addColumn('id', 'integer');
Expand All @@ -1416,9 +1416,8 @@ public function testAlterTableChangePrimaryKey() : void

$c = new Comparator();
$diff = $c->diffTable($tableFrom, $tableTo);

$this->_sm->alterTable($diff);
$tableFinal = $this->_sm->listTableDetails('primary_key_userid');
self::assertEquals(['id'], $tableFinal->getPrimaryKey()->getColumns());
$tableFinal = $this->_sm->listTableDetails('primary_key_id');
self::assertEquals(['ID'], array_map('strtoupper', $tableFinal->getPrimaryKey()->getColumns()));
}
}

0 comments on commit 2e29acd

Please sign in to comment.