summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-03-31 01:42:45 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-03-31 01:42:45 +0000
commit3dfb808a6db114abf0a8fbaa8eaa72d3624af645 (patch)
tree55586918f7c9fc0a7ffd1f13b5151ef4c1cb22e7 /includes
parent5f3033d78a068b0ef216f47c261f615fbfa4ae01 (diff)
downloadbrdo-3dfb808a6db114abf0a8fbaa8eaa72d3624af645.tar.gz
brdo-3dfb808a6db114abf0a8fbaa8eaa72d3624af645.tar.bz2
#373225 by Josh Waihi: Make PostgreSQL cast values when changing database columns to prevent data loss.
Diffstat (limited to 'includes')
-rw-r--r--includes/database/pgsql/schema.inc13
1 files changed, 12 insertions, 1 deletions
diff --git a/includes/database/pgsql/schema.inc b/includes/database/pgsql/schema.inc
index b5e0df8a6..7e6947ff7 100644
--- a/includes/database/pgsql/schema.inc
+++ b/includes/database/pgsql/schema.inc
@@ -547,9 +547,20 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
$not_null = isset($spec['not null']) ? $spec['not null'] : FALSE;
unset($spec['not null']);
+ if (!array_key_exists('size', $spec)) {
+ $spec['size'] = 'normal';
+ }
$this->addField($ret, $table, "$field_new", $spec);
- $ret[] = update_sql("UPDATE {" . $table . "} SET $field_new = " . $field . "_old");
+ // We need to typecast the new column to best be able to transfer the data
+ // Schema_pgsql::getFieldTypeMap() will return possibilities that are not
+ // 'cast-able' such as 'serial' - so they need to be casted int instead.
+ $map = $this->getFieldTypeMap();
+ $typecast = $map[$spec['type'] . ':' . $spec['size']];
+ if (in_array($typecast, array('serial', 'bigserial', 'numeric'))) {
+ $typecast = 'int';
+ }
+ $ret[] = update_sql("UPDATE {" . $table . "} SET $field_new = CAST(" . $field . "_old as " . $typecast . ")");
if ($not_null) {
$ret[] = update_sql("ALTER TABLE {" . $table . "} ALTER $field_new SET NOT NULL");