diff --git includes/database/pgsql/schema.inc includes/database/pgsql/schema.inc index cda525b..0334b19 100644 --- includes/database/pgsql/schema.inc +++ includes/database/pgsql/schema.inc @@ -470,16 +470,22 @@ class DatabaseSchema_pgsql extends DatabaseSchema { $typecast = 'int'; } + $this->connection->query("ALTER TABLE {" . $table . "} ALTER $field TYPE $typecast"); - $this->connection->query("ALTER TABLE {" . $table . "} ALTER $field SET $field_new = CAST(" . $field . "_old as " . $typecast . ")"); - - $this->addField($table, "$field_new", $spec); - - $this->dropField($table, $field . '_old'); + // If changing to a serial, create sequence. + if (in_array($map[$spec['type'] . ':' . $spec['size']], array('serial', 'bigserial'))) { + $this->connection->query("CREATE SEQUENCE {" . $table . "}_" . $field_new . "_seq"); + $this->connection->query("ALTER TABLE {" . $table . "} ALTER $field SET DEFAULT nextval('{" . $table . "}_" . $field_new . "_seq')"); + } // Rename the column if necessary. if ($field != $field_new) { - $this->connection->query('ALTER TABLE {' . $table . '} RENAME "' . $field . '" TO "' . $field_new . '_old"'); + $this->connection->query('ALTER TABLE {' . $table . '} RENAME "' . $field . '" TO "' . $field_new . '"'); + } + + // Change description if necessary. + if (!empty($spec['description'])) { + $this->connection->query('COMMENT ON COLUMN {' . $table . '}.' . $field_new . ' IS ' . $this->prepareComment($spec['description'])); } if (isset($new_keys)) {