summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-07-10 06:00:08 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-07-10 06:00:08 +0200
commitba3ebf7be5c1aebec4dcb7d166581aa164024818 (patch)
tree55b85456214e7a49ae468de15cd09c4ea304f08f
parent5d9a31729b63bf0407d955e656f50eb130344069 (diff)
downloadbugzilla-ba3ebf7be5c1aebec4dcb7d166581aa164024818.tar.gz
bugzilla-ba3ebf7be5c1aebec4dcb7d166581aa164024818.tar.xz
Bug 577793: Improve the Pg SERIAL-altering code now that we require 8.3
r=mkanat, a=mkanat (module owner)
-rw-r--r--Bugzilla/DB/Schema/Pg.pm18
1 files changed, 8 insertions, 10 deletions
diff --git a/Bugzilla/DB/Schema/Pg.pm b/Bugzilla/DB/Schema/Pg.pm
index 3559bae9c..31eedadcb 100644
--- a/Bugzilla/DB/Schema/Pg.pm
+++ b/Bugzilla/DB/Schema/Pg.pm
@@ -100,11 +100,9 @@ sub get_rename_column_ddl {
my @sql = ("ALTER TABLE $table RENAME COLUMN $old_name TO $new_name");
my $def = $self->get_column_abstract($table, $old_name);
if ($def->{TYPE} =~ /SERIAL/i) {
- # We have to rename the series also, and fix the default of the series.
- push(@sql, "ALTER TABLE ${table}_${old_name}_seq
- RENAME TO ${table}_${new_name}_seq");
- push(@sql, "ALTER TABLE $table ALTER COLUMN $new_name
- SET DEFAULT NEXTVAL('${table}_${new_name}_seq')");
+ # We have to rename the series also.
+ push(@sql, "ALTER SEQUENCE ${table}_${old_name}_seq
+ RENAME TO ${table}_${new_name}_seq");
}
return @sql;
}
@@ -147,7 +145,8 @@ sub _get_alter_type_sql {
TYPE $type");
if ($new_def->{TYPE} =~ /serial/i && $old_def->{TYPE} !~ /serial/i) {
- push(@statements, "CREATE SEQUENCE ${table}_${column}_seq");
+ push(@statements, "CREATE SEQUENCE ${table}_${column}_seq
+ OWNED BY $table.$column");
push(@statements, "SELECT setval('${table}_${column}_seq',
MAX($table.$column))
FROM $table");
@@ -160,10 +159,9 @@ sub _get_alter_type_sql {
if ($old_def->{TYPE} =~ /serial/i && $new_def->{TYPE} !~ /serial/i) {
push(@statements, "ALTER TABLE $table ALTER COLUMN $column
DROP DEFAULT");
- # XXX Pg actually won't let us drop the sequence, even though it's
- # no longer in use. So we harmlessly leave behind a sequence
- # that does nothing.
- #push(@statements, "DROP SEQUENCE ${table}_${column}_seq");
+ push(@statements, "ALTER SEQUENCE ${table}_${column}_seq
+ OWNED BY NONE");
+ push(@statements, "DROP SEQUENCE ${table}_${column}_seq");
}
return @statements;