297a298
>     // TODO: rename sequences (is this really necessary?)
473a475
>     $this->connection->query('ALTER TABLE {' . $table . '} ALTER "' . $field . '" TYPE ' . $typecast . ' USING "' . $field . '"::' . $typecast);
475,479c477,488
<     $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'))) {
>       // NB. type "serial" is known to postgres, but *only* during table creation, not when altering!
>       $seq = "{" . $table . "}_" . $field_new . "_seq";
>       $this->connection->query("CREATE SEQUENCE " . $seq);
>       // set sequence to maximal field value in order not to conflict with existing ids
>       $this->connection->query("SELECT setval('" . $seq . "', MAX(" . $field . ")) FROM {" . $table . "}");      
>       $this->connection->query('ALTER TABLE {' . $table . '} ALTER "' . $field . '" SET DEFAULT nextval(\'' . $seq . '\')');
>     }
>     // TODO: if changing NOT TO BE serial any more, delete sequence and default value
>     
>     // TODO: it is not possible right now to change the NULL/NOT NULL nature of fields
483c492,498
<       $this->connection->query('ALTER TABLE {' . $table . '} RENAME "' . $field . '" TO "' . $field_new . '_old"');
---
>       $this->connection->query('ALTER TABLE {' . $table . '} RENAME "' . $field . '" TO "' . $field_new . '"');
>     }
>     // TODO: rename any indexes, if necessary
> 
>     // Change description if necessary.
>     if (!empty($spec['description'])) {
>       $this->connection->query('COMMENT ON COLUMN {' . $table . '}.' . $field_new . ' IS ' . $this->prepareComment($spec['description']));
