mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
Merge pull request #33 from silverstripe/fixes/ifindexexists
FIX: Check index exists before dropping
This commit is contained in:
commit
f3574a616b
@ -395,8 +395,9 @@ class MSSQLSchemaManager extends DBSchemaManager
|
|||||||
// drop *ALL* indexes on a table before proceeding
|
// drop *ALL* indexes on a table before proceeding
|
||||||
// this won't drop primary keys, though
|
// this won't drop primary keys, though
|
||||||
$indexes = $this->indexNames($tableName);
|
$indexes = $this->indexNames($tableName);
|
||||||
|
|
||||||
foreach ($indexes as $indexName) {
|
foreach ($indexes as $indexName) {
|
||||||
$alterQueries[] = "DROP INDEX \"$indexName\" ON \"$tableName\";";
|
$alterQueries[] = "\nIF EXISTS (SELECT name FROM sys.indexes WHERE name = '$indexName' AND object_id = object_id('schema.$tableName')) DROP INDEX \"$indexName\" ON \"$tableName\";";
|
||||||
}
|
}
|
||||||
|
|
||||||
$prefix = "ALTER TABLE \"$tableName\" ";
|
$prefix = "ALTER TABLE \"$tableName\" ";
|
||||||
|
Loading…
Reference in New Issue
Block a user