mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-07-01 00:49:35 +02:00
MINOR: data types now identify themselves more clearly, to prevent needless rebuilds in dev/build
This commit is contained in:
parent
a27ca9a55a
commit
e2edf8dc16
|
@ -572,12 +572,15 @@ class PostgreSQLDatabase extends SS_Database {
|
||||||
$constraint_bits=explode('(', $matches[4]);
|
$constraint_bits=explode('(', $matches[4]);
|
||||||
$constraint_values=trim($constraint_bits[2], ')');
|
$constraint_values=trim($constraint_bits[2], ')');
|
||||||
$constraint_values_bits=explode(',', $constraint_values);
|
$constraint_values_bits=explode(',', $constraint_values);
|
||||||
$default=trim($constraint_values[0], " '");
|
$default=trim($constraint_values_bits[0], " '");
|
||||||
//Now go and convert anything that's not in this list to the first thing in the enum list
|
|
||||||
|
//Now go and convert anything that's not in this list to 'Page'
|
||||||
//We have to run this as a query, not as part of the alteration queries due to the way they are constructed.
|
//We have to run this as a query, not as part of the alteration queries due to the way they are constructed.
|
||||||
$updateConstraint='';
|
$updateConstraint='';
|
||||||
$updateConstraint.="UPDATE \"{$tableName}\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
|
$updateConstraint.="UPDATE \"{$tableName}\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
|
||||||
|
if($this->hasTable("{$tableName}_Live"))
|
||||||
$updateConstraint.="UPDATE \"{$tableName}_Live\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
|
$updateConstraint.="UPDATE \"{$tableName}_Live\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
|
||||||
|
if($this->hasTable("{$tableName}_versions"))
|
||||||
$updateConstraint.="UPDATE \"{$tableName}_versions\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
|
$updateConstraint.="UPDATE \"{$tableName}_versions\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
|
||||||
|
|
||||||
DB::query($updateConstraint);
|
DB::query($updateConstraint);
|
||||||
|
@ -702,11 +705,11 @@ class PostgreSQLDatabase extends SS_Database {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'numeric':
|
case 'numeric':
|
||||||
$output[$field['column_name']]='decimal(' . $field['numeric_precision'] . ',' . $field['numeric_scale'] . ') default ' . $field['column_default'];
|
$output[$field['column_name']]='decimal(' . $field['numeric_precision'] . ',' . $field['numeric_scale'] . ') default ' . (int)$field['column_default'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'integer':
|
case 'integer':
|
||||||
$output[$field['column_name']]='integer default ' . $field['column_default'];
|
$output[$field['column_name']]='integer default ' . (int)$field['column_default'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'timestamp without time zone':
|
case 'timestamp without time zone':
|
||||||
|
@ -714,7 +717,7 @@ class PostgreSQLDatabase extends SS_Database {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'smallint':
|
case 'smallint':
|
||||||
$output[$field['column_name']]='smallint default ' . $field['column_default'];
|
$output[$field['column_name']]='smallint default ' . (int)$field['column_default'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'time without time zone':
|
case 'time without time zone':
|
||||||
|
@ -761,18 +764,18 @@ class PostgreSQLDatabase extends SS_Database {
|
||||||
case 'fulltext':
|
case 'fulltext':
|
||||||
//We need to include the fields so if we change the columns it's indexing, but not the name,
|
//We need to include the fields so if we change the columns it's indexing, but not the name,
|
||||||
//then the change will be picked up.
|
//then the change will be picked up.
|
||||||
$indexSpec='(ts_' . $indexSpec['name'] . '_' . $indexSpec['value'] . ')';
|
$indexSpec='(' . $indexSpec['name'] . ',' . $indexSpec['value'] . ')';
|
||||||
break;
|
break;
|
||||||
case 'unique':
|
case 'unique':
|
||||||
$indexSpec='unique (' . $indexSpec['value'] . ')';
|
$indexSpec='unique (' . $indexSpec['value'] . ')';
|
||||||
break;
|
break;
|
||||||
case 'hash':
|
case 'hash':
|
||||||
$indexSpec='(' . $indexSpec['value'] . ')';
|
$indexSpec='using hash (' . $indexSpec['value'] . ')';
|
||||||
break;
|
break;
|
||||||
case 'index':
|
case 'index':
|
||||||
//The default index is 'btree', which we'll use by default (below):
|
//The default index is 'btree', which we'll use by default (below):
|
||||||
default:
|
default:
|
||||||
$indexSpec='(' . $indexSpec['value'] . ')';
|
$indexSpec='using btree (' . $indexSpec['value'] . ')';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1261,9 +1264,10 @@ class PostgreSQLDatabase extends SS_Database {
|
||||||
if(!isset($values['arrayValue']))
|
if(!isset($values['arrayValue']))
|
||||||
$values['arrayValue']='';
|
$values['arrayValue']='';
|
||||||
|
|
||||||
|
//TODO: the DbValue result does not include the numeric_scale option (ie, the ,0 value in 4,0)
|
||||||
if($asDbValue)
|
if($asDbValue)
|
||||||
return Array('data_type'=>'numeric', 'precision'=>'4');
|
return Array('data_type'=>'decimal', 'precision'=>'4', 'default'=> (int)$values['default']);
|
||||||
else return "numeric(4){$values['arrayValue']}";
|
else return "decimal(4,0){$values['arrayValue']}";
|
||||||
}
|
}
|
||||||
|
|
||||||
function escape_character($escape=false){
|
function escape_character($escape=false){
|
||||||
|
|
Loading…
Reference in New Issue
Block a user