]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 508181: UTF-8 table conversion was failing when there were FKs on the column...
authormkanat%bugzilla.org <>
Thu, 6 Aug 2009 14:54:21 +0000 (14:54 +0000)
committermkanat%bugzilla.org <>
Thu, 6 Aug 2009 14:54:21 +0000 (14:54 +0000)
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=mkanat

Bugzilla/DB.pm
Bugzilla/DB/Mysql.pm

index 4bf0643751f9746f1990613d8d27ddd535ebfeb5..9ede5bd805e396ad42aa47d17e77d6fc1a5bcc31 100644 (file)
@@ -747,6 +747,28 @@ sub bz_drop_fk {
 
 }
 
+sub bz_drop_related_fks {
+    my ($self, $table, $column) = @_;
+    my @tables = $self->_bz_real_schema->get_table_list();
+    my @dropped;
+    foreach my $check_table (@tables) {
+        my @columns = $self->bz_table_columns($check_table);
+        foreach my $check_column (@columns) {
+            my $def = $self->bz_column_info($check_table, $check_column);
+            my $fk = $def->{REFERENCES};
+            if ($fk 
+                and (($fk->{TABLE} eq $table and $fk->{COLUMN} eq $column)
+                     or ($check_column eq $column and $check_table eq $table)))
+            {
+                $self->bz_drop_fk($check_table, $check_column);
+                push(@dropped, [$check_table, $check_column, $fk]); 
+            }
+        } # foreach $column
+    } # foreach $table
+
+    return \@dropped;
+}
+
 sub bz_drop_index {
     my ($self, $table, $name) = @_;
 
index f06900f1b91967c9a571de57e66daa27123a5eb6..45e181d3f3dbb96b7a6526f11c893a39bd095cc8 100644 (file)
@@ -713,6 +713,7 @@ EOT
 
         print "Converting table storage format to UTF-8. This may take a",
               " while.\n";
+        my @dropped_fks;
         foreach my $table ($self->bz_table_list_real) {
             my $info_sth = $self->prepare("SHOW FULL COLUMNS FROM $table");
             $info_sth->execute();
@@ -746,13 +747,15 @@ EOT
                         }
                     }
 
+                    my $dropped = $self->bz_drop_related_fks($table, $name);
+                    push(@dropped_fks, @$dropped);
+
                     print "Converting $table.$name to be stored as UTF-8...\n";
                     my $col_info = 
                         $self->bz_column_info_real($table, $name);
 
                     # CHANGE COLUMN doesn't take PRIMARY KEY
                     delete $col_info->{PRIMARYKEY};
-
                     my $sql_def = $self->_bz_schema->get_type_ddl($col_info);
                     # We don't want MySQL to actually try to *convert*
                     # from our current charset to UTF-8, we just want to
@@ -779,7 +782,12 @@ EOT
             }
 
             $self->do("ALTER TABLE $table DEFAULT CHARACTER SET utf8");
+
         } # foreach my $table (@tables)
+
+        foreach my $fk_args (@dropped_fks) {
+            $self->bz_add_fk(@$fk_args);
+        }
     }
 
     # Sometimes you can have a situation where all the tables are utf8,