diff options
author | mkanat%kerio.com <> | 2005-04-17 14:24:13 +0000 |
---|---|---|
committer | mkanat%kerio.com <> | 2005-04-17 14:24:13 +0000 |
commit | 8231d98d0644c387ea8476f61b4a3301848403d9 (patch) | |
tree | 7c7783053928ac0f548bfb529e5003557da27b7e /Bugzilla | |
parent | 77691d57c478404d33235d45cb94156efd3a95f2 (diff) | |
download | bugs-8231d98d0644c387ea8476f61b4a3301848403d9.tar bugs-8231d98d0644c387ea8476f61b4a3301848403d9.tar.gz bugs-8231d98d0644c387ea8476f61b4a3301848403d9.tar.bz2 bugs-8231d98d0644c387ea8476f61b4a3301848403d9.tar.xz bugs-8231d98d0644c387ea8476f61b4a3301848403d9.zip |
Bug 290403: Slight cleanup of Bugzilla::DB index code
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=justdave
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/DB.pm | 62 | ||||
-rw-r--r-- | Bugzilla/DB/Mysql.pm | 27 |
2 files changed, 56 insertions, 33 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index 3a52e8802..a32406d5b 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -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) = @_; diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm index aed2b89fb..cb7cdbe7e 100644 --- a/Bugzilla/DB/Mysql.pm +++ b/Bugzilla/DB/Mysql.pm @@ -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 |