summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Pg.pm
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@gmail.com>2011-12-26 11:31:15 +0100
committerFrédéric Buclin <LpSolit@gmail.com>2011-12-26 11:31:15 +0100
commit429534ee24bfbfce0c330b92e0167b4c8cff6b5f (patch)
treeb9371d4d87fbd39f9d2451061f13b40b09eb29fc /Bugzilla/DB/Pg.pm
parente647ec0703c903e4f64fad385ff39465f6f83ce0 (diff)
downloadbugzilla-429534ee24bfbfce0c330b92e0167b4c8cff6b5f.tar.gz
bugzilla-429534ee24bfbfce0c330b92e0167b4c8cff6b5f.tar.xz
Bug 683644: Foreign keys aren't renamed correctly when DB tables are renamed
r=wicked a=LpSolit
Diffstat (limited to 'Bugzilla/DB/Pg.pm')
-rw-r--r--Bugzilla/DB/Pg.pm34
1 files changed, 26 insertions, 8 deletions
diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm
index e59a638a4..b6be64011 100644
--- a/Bugzilla/DB/Pg.pm
+++ b/Bugzilla/DB/Pg.pm
@@ -282,14 +282,18 @@ END
$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')");
+ # bz_rename_column and bz_rename_table didn't correctly rename
+ # the sequence.
+ $self->_fix_bad_sequence('fielddefs', 'id', 'fielddefs_fieldid_seq', 'fielddefs_id_seq');
+ # If the 'tags' table still exists, then bz_rename_table()
+ # will fix the sequence for us.
+ if (!$self->bz_table_info('tags')) {
+ my $res = $self->_fix_bad_sequence('tag', 'id', 'tags_id_seq', 'tag_id_seq');
+ # If $res is true, then the sequence has been renamed, meaning that
+ # the primary key must be renamed too.
+ if ($res) {
+ $self->do('ALTER INDEX tags_pkey RENAME TO tag_pkey');
+ }
}
# Certain sequences got upgraded before we required Pg 8.3, and
@@ -320,6 +324,20 @@ END
}
}
+sub _fix_bad_sequence {
+ my ($self, $table, $column, $old_seq, $new_seq) = @_;
+ if ($self->bz_column_info($table, $column)
+ && $self->bz_sequence_exists($old_seq))
+ {
+ print "Fixing $old_seq sequence...\n";
+ $self->do("ALTER SEQUENCE $old_seq RENAME TO $new_seq");
+ $self->do("ALTER TABLE $table ALTER COLUMN $column
+ SET DEFAULT NEXTVAL('$new_seq')");
+ return 1;
+ }
+ return 0;
+}
+
# Renames things that differ only in case.
sub _fix_case_differences {
my ($table, $field) = @_;