Merge branch '1.0' into 1.1

This commit is contained in:
Daniel Hensby 2017-07-26 11:52:50 +01:00
commit 1a78f20b8a
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E

View File

@ -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 : '';
@ -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);
} }