mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
MINOR FIX: ID column protected against index and column alterations
This commit is contained in:
parent
82dcbb89d2
commit
396384e709
@ -461,8 +461,11 @@ class MSSQLDatabase extends Database {
|
||||
|
||||
//drop the index if it exists:
|
||||
$alterCol='';
|
||||
if(isset($indexList[$colName])){
|
||||
$alterCol = "\nDROP INDEX \"$tableName\".ix_{$tableName}_{$colName};";
|
||||
if(isset($indexList[$colName]) && $colName!='ID'){
|
||||
//$alterCol = "\nDROP INDEX \"$tableName\".ix_{$tableName}_{$colName};";
|
||||
//The indexname value should hold the name of the index, so we don't have to construct it outselves.
|
||||
//This also means we can use internal indexes if they happen to appear.
|
||||
$alterCol = "\nDROP INDEX \"$tableName\"." . $indexList[$colName]['indexname'] . ';';
|
||||
}
|
||||
|
||||
$prefix="ALTER TABLE \"" . $tableName . "\" ";
|
||||
@ -473,6 +476,8 @@ class MSSQLDatabase extends Database {
|
||||
}
|
||||
|
||||
if(isset($matches[1])) {
|
||||
//We will prevent any changes being made to the ID column. Primary key indexes will have a fit if we do anything here.
|
||||
if($colName!='ID'){
|
||||
$alterCol .= ";\n$prefix ALTER COLUMN \"$colName\" $matches[1]";
|
||||
|
||||
// SET null / not null
|
||||
@ -493,6 +498,7 @@ class MSSQLDatabase extends Database {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return isset($alterCol) ? $alterCol : '';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user