Commit a880811a authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-126 - Special case for dropping MySQL Primary keys

parent 4c383bd8
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
namespace Doctrine\DBAL\Platforms; namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\DBALException, use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Schema\TableDiff; Doctrine\DBAL\Schema\TableDiff,
Doctrine\DBAL\Schema\Index,
Doctrine\DBAL\Schema\Table;
/** /**
* The MySqlPlatform provides the behavior, features and SQL dialect of the * The MySqlPlatform provides the behavior, features and SQL dialect of the
...@@ -576,20 +578,37 @@ class MySqlPlatform extends AbstractPlatform ...@@ -576,20 +578,37 @@ class MySqlPlatform extends AbstractPlatform
* @override * @override
*/ */
public function getDropIndexSQL($index, $table=null) public function getDropIndexSQL($index, $table=null)
{ {
if($index instanceof \Doctrine\DBAL\Schema\Index) { if($index instanceof Index) {
$index = $index->getQuotedName($this); $indexName = $index->getQuotedName($this);
} else if(!is_string($index)) { } else if(is_string($index)) {
$indexName = $index;
} else {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
} }
if($table instanceof \Doctrine\DBAL\Schema\Table) { if($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} else if(!is_string($table)) { } else if(!is_string($table)) {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
} }
if ($index instanceof Index && $index->isPrimary()) {
// mysql primary keys are always named "PRIMARY",
// so we cannot use them in statements because of them being keyword.
return $this->getDropPrimaryKeySQL($table);
}
return 'DROP INDEX ' . $index . ' ON ' . $table; return 'DROP INDEX ' . $indexName . ' ON ' . $table;
}
/**
* @param Index $index
* @param Table $table
*/
protected function getDropPrimaryKeySQL($table)
{
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
} }
/** /**
......
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