mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 15:05:45 +00:00
Merge branch '1.0' into 1.1
This commit is contained in:
commit
1a78f20b8a
@ -743,7 +743,8 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SET check constraint (The constraint HAS to be dropped)
|
// SET check constraint (The constraint HAS to be dropped)
|
||||||
$existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$tableName}_{$colName}_check';")->value();
|
$constraint_name = "{$tableName}_{$colName}_check";
|
||||||
|
$existing_constraint = $this->constraintExists($constraint_name);
|
||||||
if(isset($matches[4])) {
|
if(isset($matches[4])) {
|
||||||
//Take this new constraint and see what's outstanding from the target table:
|
//Take this new constraint and see what's outstanding from the target table:
|
||||||
$constraint_bits=explode('(', $matches[4]);
|
$constraint_bits=explode('(', $matches[4]);
|
||||||
@ -767,11 +768,11 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
//First, delete any existing constraint on this column, even if it's no longer an enum
|
//First, delete any existing constraint on this column, even if it's no longer an enum
|
||||||
if($existing_constraint)
|
if($existing_constraint)
|
||||||
$alterCol .= ",\nDROP CONSTRAINT \"{$tableName}_{$colName}_check\"";
|
$alterCol .= ",\nDROP CONSTRAINT \"{$constraint_name}\"";
|
||||||
|
|
||||||
//Now create the constraint (if we've asked for one)
|
//Now create the constraint (if we've asked for one)
|
||||||
if(!empty($matches[4]))
|
if(!empty($matches[4]))
|
||||||
$alterCol .= ",\nADD CONSTRAINT \"{$tableName}_{$colName}_check\" $matches[4]";
|
$alterCol .= ",\nADD CONSTRAINT \"{$constraint_name}\" $matches[4]";
|
||||||
}
|
}
|
||||||
|
|
||||||
return isset($alterCol) ? $alterCol : '';
|
return isset($alterCol) ? $alterCol : '';
|
||||||
@ -1138,16 +1139,16 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
|
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
|
||||||
*/
|
*/
|
||||||
public function alterIndex($tableName, $indexName, $indexSpec) {
|
public function alterIndex($tableName, $indexName, $indexSpec) {
|
||||||
$indexSpec = trim($indexSpec);
|
$indexSpec = trim($indexSpec);
|
||||||
if($indexSpec[0] != '(') {
|
if($indexSpec[0] != '(') {
|
||||||
list($indexType, $indexFields) = explode(' ',$indexSpec,2);
|
list($indexType, $indexFields) = explode(' ',$indexSpec,2);
|
||||||
} else {
|
} else {
|
||||||
$indexFields = $indexSpec;
|
$indexFields = $indexSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$indexType) {
|
if(!$indexType) {
|
||||||
$indexType = "index";
|
$indexType = "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->query("DROP INDEX \"$indexName\"");
|
$this->query("DROP INDEX \"$indexName\"");
|
||||||
$this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields");
|
$this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields");
|
||||||
@ -2024,9 +2025,10 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
DB::query("CREATE TABLE \"$partition_name\" (CHECK (" . str_replace('NEW.', '', $partition_value) . ")) INHERITS (\"$tableName\")$tableSpace;");
|
DB::query("CREATE TABLE \"$partition_name\" (CHECK (" . str_replace('NEW.', '', $partition_value) . ")) INHERITS (\"$tableName\")$tableSpace;");
|
||||||
} else {
|
} else {
|
||||||
//Drop the constraint, we will recreate in in the next line
|
//Drop the constraint, we will recreate in in the next line
|
||||||
$existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$partition_name}_pkey';");
|
$constraint_name = "{$partition_name}_pkey";
|
||||||
|
$existing_constraint = $this->constraintExists($constraint_name);
|
||||||
if($existing_constraint){
|
if($existing_constraint){
|
||||||
DB::query("ALTER TABLE \"$partition_name\" DROP CONSTRAINT \"{$partition_name}_pkey\";");
|
DB::query("ALTER TABLE \"$partition_name\" DROP CONSTRAINT \"{$constraint_name}\";");
|
||||||
}
|
}
|
||||||
$this->dropTrigger(strtolower('trigger_' . $tableName . '_insert'), $tableName);
|
$this->dropTrigger(strtolower('trigger_' . $tableName . '_insert'), $tableName);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user