]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 290403: Slight cleanup of Bugzilla::DB index code
authormkanat%kerio.com <>
Sun, 17 Apr 2005 14:24:13 +0000 (14:24 +0000)
committermkanat%kerio.com <>
Sun, 17 Apr 2005 14:24:13 +0000 (14:24 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=justdave

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

index 3a52e88023a4e0d4a5c0181ddf450f652cf47c29..a32406d5bc161c0aaf45a1b64609c7fdcb7d48d2 100644 (file)
@@ -414,17 +414,36 @@ sub bz_add_index {
     my $index_exists = $self->bz_index_info($table, $name);
 
     if (!$index_exists) {
-        my @statements = $self->_bz_real_schema->get_add_index_ddl(
-            $table, $name, $definition);
-        print "Adding new index '$name' to the $table table ...\n";
-        foreach my $sql (@statements) {
-            $self->do($sql);
-        }
+        $self->_bz_add_index_raw($table, $name, $definition);
         $self->_bz_real_schema->set_index($table, $name, $definition);
         $self->_bz_store_real_schema;
     }
 }
 
+# bz_add_index_raw($table, $name, $silent)
+#
+# Description: A helper function for bz_add_index.
+#              Adds an index to the database
+#              without updating any Schema object. Generally
+#              should only be called by bz_add_index.
+#              Used when you don't yet have a Schema
+#              object but you need to add an index, for some reason.
+# Params:      $table  - The name of the table the index is on.
+#              $name   - The name of the index you're adding.
+#              $definition - The abstract index definition, in hashref
+#                            or arrayref format.
+#              $silent - (optional) If specified and true, don't output
+#                        any message about this change.
+# Returns:     nothing
+#
+sub bz_add_index_raw {
+    my ($self, $table, $name, $definition, $silent) = @_;
+    my @statements = $self->_bz_schema->get_add_index_ddl(
+        $table, $name, $definition);
+    print "Adding new index '$name' to the $table table ...\n" unless $silent;
+    $self->do($_) foreach (@statements);
+}
+
 sub bz_add_table {
     my ($self, $name) = @_;
 
@@ -520,17 +539,36 @@ sub bz_drop_index {
     my $index_exists = $self->bz_index_info($table, $name);
 
     if ($index_exists) {
-        my @statements = $self->_bz_real_schema->get_drop_index_ddl(
-            $table, $name);
-        print "Removing index '$name' from the $table table...\n";
-        foreach my $sql (@statements) {
-            $self->do($sql);
-        }
+        $self->_bz_drop_index_raw($table, $name);
         $self->_bz_real_schema->delete_index($table, $name);
         $self->_bz_store_real_schema;        
     }
 }
 
+# bz_drop_index_raw($table, $name, $silent)
+#
+# Description: A helper function for bz_drop_index.
+#              Drops an index from the database
+#              without updating any Schema object. Generally
+#              should only be called by bz_drop_index.
+#              Used when either: (1) You don't yet have a Schema 
+#              object but you need to drop an index, for some reason.
+#              (2) You need to drop an index that somehow got into the
+#              database but doesn't exist in Schema.
+# Params:      $table  - The name of the table the index is on.
+#              $name   - The name of the index you're dropping.
+#              $silent - (optional) If specified and true, don't output
+#                        any message about this change.
+# Returns:     nothing
+#
+sub bz_drop_index_raw {
+    my ($self, $table, $name, $silent) = @_;
+    my @statements = $self->_bz_schema->get_drop_index_ddl(
+        $table, $name);
+    print "Removing index '$name' from the $table table...\n" unless $silent;
+    $self->do($_) foreach (@statements);
+}
+
 # XXX - Needs to be made cross-db compatible
 sub bz_drop_table_indexes ($) {
     my ($self, $table) = @_;
index aed2b89fb96e9d50617f7c1376de037477f41bdc..cb7cdbe7ed455893e2e45d70a62b457c71bcc538 100644 (file)
@@ -304,16 +304,7 @@ sub bz_setup_database {
             elsif ($self->bz_index_info_real('series', 'series_creator_idx')) {
                     $dropname = 'series_creator_idx';
             }
-
-            if ($dropname) {
-                print "Removing the useless index $dropname on the"
-                      . " series table...\n";
-                my @drop = $self->_bz_schema->get_drop_index_ddl(
-                    'series', $dropname);
-                foreach my $sql (@drop) {
-                    $self->do($sql);
-                }
-            }
+            $self->bz_drop_index_raw('series', $dropname) if $dropname;
         }
 
         # The email_setting table also had the same problem.
@@ -321,11 +312,8 @@ sub bz_setup_database {
             && $self->bz_index_info_real('email_setting', 
                                          'email_settings_user_id_idx') ) 
         {
-            print "Removing the useless index email_settings_user_id_idx\n"
-                  . "  on the email_setting table...\n";
-            my @drop = $self->_bz_schema->get_drop_index_ddl('email_setting',
-                'email_settings_user_id_idx');
-            $self->do($_) foreach (@drop);
+            $self->bz_drop_index_raw('email_setting', 
+                                     'email_settings_user_id_idx');
         }
 
         # Go through all the tables.
@@ -361,12 +349,9 @@ sub bz_setup_database {
                     print "Renaming index $column to to $new_name...\n";
                     # Unfortunately, MySQL has no way to rename an index. :-(
                     # So we have to drop and recreate the indexes.
-                    my @drop = $self->_bz_schema->get_drop_index_ddl(
-                        $table, $column);
-                    my @add = $self->_bz_schema->get_add_index_ddl(
-                        $table, $new_name, $index);
-                    $self->do($_) foreach (@drop);
-                    $self->do($_) foreach (@add);
+                    $self->bz_drop_index_raw($table, $column, "silent");
+                    $self->bz_add_index_raw($table, $new_name, 
+                                             $index, "silent");
                 } # if
             } # foreach column
         } # foreach table