summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Pg.pm
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2006-11-01 08:27:31 +0100
committermkanat%bugzilla.org <>2006-11-01 08:27:31 +0100
commit89edfad4a52a2924dbf2d67d5609870e1200f7d3 (patch)
tree12d28d0e870419bb989488ad7f9ced11742cb012 /Bugzilla/DB/Pg.pm
parente698452f3a2e5a04e291b880c2d823b098c0714a (diff)
downloadbugzilla-89edfad4a52a2924dbf2d67d5609870e1200f7d3.tar.gz
bugzilla-89edfad4a52a2924dbf2d67d5609870e1200f7d3.tar.xz
Bug 358956: [PostgreSQL] Sequences need to be renamed when their field is renamed
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=myk
Diffstat (limited to 'Bugzilla/DB/Pg.pm')
-rw-r--r--Bugzilla/DB/Pg.pm19
1 files changed, 19 insertions, 0 deletions
diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm
index 98bfc5903..ff596ad0d 100644
--- a/Bugzilla/DB/Pg.pm
+++ b/Bugzilla/DB/Pg.pm
@@ -207,6 +207,15 @@ sub bz_unlock_tables {
}
}
+# Tell us whether or not a particular sequence exists in the DB.
+sub bz_sequence_exists {
+ my ($self, $seq_name) = @_;
+ my $exists = $self->selectrow_array(
+ 'SELECT 1 FROM pg_statio_user_sequences WHERE relname = ?',
+ undef, $seq_name);
+ return $exists || 0;
+}
+
#####################################################################
# Custom Database Setup
#####################################################################
@@ -236,6 +245,16 @@ sub bz_setup_database {
_fix_case_differences('products', 'name');
$self->bz_add_index('products', 'products_name_lower_idx',
{FIELDS => ['LOWER(name)'], TYPE => 'UNIQUE'});
+
+ # bz_rename_column didn't correctly rename the sequence.
+ if ($self->bz_column_info('fielddefs', 'id')
+ && $self->bz_sequence_exists('fielddefs_fieldid_seq'))
+ {
+ print "Fixing fielddefs_fieldid_seq sequence...\n";
+ $self->do("ALTER TABLE fielddefs_fieldid_seq RENAME TO fielddefs_id_seq");
+ $self->do("ALTER TABLE fielddefs ALTER COLUMN id
+ SET DEFAULT NEXTVAL('fielddefs_id_seq')");
+ }
}
# Renames things that differ only in case.