Skip to content

Commit

Permalink
DBAL-2925: added dropPrimaryKeySQL() method to platform. Used to fix …
Browse files Browse the repository at this point in the history
…primary key management bug
  • Loading branch information
SCIF committed Dec 5, 2017
1 parent c7ca968 commit 6333a15
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
15 changes: 15 additions & 0 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,11 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
$sql[] = $this->getDropIndexSQL($index, $tableName);
}
foreach ($diff->changedIndexes as $index) {
if ($index->isPrimary()) {
$sql[] = $this->getDropPrimaryKeySQL($tableName);
continue;
}

$sql[] = $this->getDropIndexSQL($index, $tableName);
}

Expand Down Expand Up @@ -3570,4 +3575,14 @@ public function getStringLiteralQuoteCharacter()
{
return "'";
}

/**
* @param string $table
*
* @return string
*/
protected function getDropPrimaryKeySQL(string $table): string
{
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
}
}
8 changes: 0 additions & 8 deletions lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,6 @@ public function getDropIndexSQL($index, $table=null)
return 'DROP INDEX ' . $indexName . ' ON ' . $table;
}

/**
* {@inheritDoc}
*/
protected function getDropPrimaryKeySQL($table)
{
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
}

/**
* {@inheritDoc}
*/
Expand Down
10 changes: 0 additions & 10 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,16 +976,6 @@ public function getDropIndexSQL($index, $table=null)
return 'DROP INDEX ' . $indexName . ' ON ' . $table;
}

/**
* @param string $table
*
* @return string
*/
protected function getDropPrimaryKeySQL($table)
{
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
}

/**
* {@inheritDoc}
*/
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,14 @@ public function getDropForeignKeySQL($foreignKey, $table)
return $this->getDropConstraintSQL($foreignKey, $table);
}

/**
* {@inheritDoc}
*/
protected function getDropPrimaryKeySQL(string $table): string
{
return $this->getDropConstraintSQL("{$table}_pkey", $table);
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 6333a15

Please sign in to comment.