From 5e655777fbdbb93348807308a045fca3cb4c7ab2 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Mon, 12 Jul 2010 16:17:51 -0700 Subject: Bug 578197: [PostgreSQL] Properly associate sequences that had no column association r=mkanat, a=mkanat (module owner) --- Bugzilla/DB/Pg.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm index 7aaafd88f..8ed7368aa 100644 --- a/Bugzilla/DB/Pg.pm +++ b/Bugzilla/DB/Pg.pm @@ -278,6 +278,27 @@ END $self->do("ALTER TABLE fielddefs ALTER COLUMN id SET DEFAULT NEXTVAL('fielddefs_id_seq')"); } + + # Certain sequences got upgraded before we required Pg 8.3, and + # so they were not properly associated with their columns. + my @tables = $self->bz_table_list_real; + foreach my $table (@tables) { + my @columns = $self->bz_table_columns_real($table); + foreach my $column (@columns) { + # All our SERIAL pks have "id" in their name at the end. + next unless $column =~ /id$/; + my $sequence = "${table}_${column}_seq"; + if ($self->bz_sequence_exists($sequence)) { + my $is_associated = $self->selectrow_array( + 'SELECT pg_get_serial_sequence(?,?)', + undef, $table, $column); + next if $is_associated; + print "Fixing $sequence to be associated" + . " with $table.$column...\n"; + $self->do("ALTER SEQUENCE $sequence OWNED BY $table.$column"); + } + } + } } # Renames things that differ only in case. -- cgit v1.2.3-24-g4f1b