Skip to content

Commit

Permalink
MsSQL fixes and CS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SCIF committed Mar 30, 2018
1 parent 2e29acd commit e9b62f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
foreach ($diff->changedIndexes as $index) {
if ($index->isPrimary()) {
$sql[] = $this->getDropPrimaryKeySQL($tableName);

continue;
}

Expand Down
14 changes: 14 additions & 0 deletions lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1619,4 +1619,18 @@ private function generateIdentifierName($identifier)

return strtoupper(dechex(crc32($identifier->getName())));
}

protected function getDropPrimaryKeySQL(string $table) : string
{
return "
DECLARE @table NVARCHAR(512), @sql NVARCHAR(MAX);
SELECT @table = N'{$table}';
SELECT @sql = 'ALTER TABLE ' + @table + ' DROP CONSTRAINT + name + ';'
FROM sys.key_constraints
WHERE [type] = 'PK'
AND [parent_object_id] = OBJECT_ID(@table);
EXEC sp_executeSQL @sql;";
}

}

0 comments on commit e9b62f7

Please sign in to comment.