]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 578197: [PostgreSQL] Properly associate sequences that had no
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Mon, 12 Jul 2010 23:17:51 +0000 (16:17 -0700)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Mon, 12 Jul 2010 23:17:51 +0000 (16:17 -0700)
column association
r=mkanat, a=mkanat (module owner)

Bugzilla/DB/Pg.pm

index 7aaafd88f32da89399249b98e7430e657e02e1f7..8ed7368aadb1d06938885d2b2836d5b9e86d7781 100644 (file)
@@ -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.