From 92a03ffda6ec6f57cf6f1068dc8e51fb5040e9a4 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 6 Aug 2010 14:31:10 -0600 Subject: [PATCH] Fix creation of postgres sequence tables --- framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php b/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php index a4d0ca286..4df3e7124 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php +++ b/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php @@ -549,9 +549,17 @@ class Horde_Db_Adapter_Postgresql_Schema extends Horde_Db_Adapter_Base_Schema $default = isset($options['default']) ? $options['default'] : null; if ($autoincrement) { - $seq_name = $this->quoteSequenceName($this->defaultSequenceName($tableName, $columnName)); + $seq_name = $this->defaultSequenceName($tableName, $columnName); + if ($this->table($seq_name)) { + $this->execute('DROP SEQUENCE ' . $seq_name . ' CASCADE'); + } $this->execute('CREATE SEQUENCE ' . $seq_name); - $this->changeColumnDefault($tableName, $columnName, 'NEXTVAL(' . $seq_name . ')'); + + /* Can't use changeColumnDefault() since it quotes the + * default value (NEXTVAL is a postgres keyword, not a text + * value). */ + $this->_clearTableCache($tableName); + $this->execute('ALTER TABLE ' . $this->quoteTableName($tableName) . ' ALTER COLUMN ' . $this->quoteColumnName($columnName) . ' SET DEFAULT NEXTVAL(' . $this->quoteSequenceName($seq_name) . ')'); } elseif (array_key_exists('default', $options)) { $this->changeColumnDefault($tableName, $columnName, $default); } -- 2.11.0