summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB.pm
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-03-22 17:56:52 +0100
committermkanat%kerio.com <>2005-03-22 17:56:52 +0100
commit946aa2272f2789fbdae896d8534cb18d9df75129 (patch)
tree7cc88c0e00775c5cc011799395aead3c686281fa /Bugzilla/DB.pm
parent7ee3130c4a11184083126394fcabe932ecc234d5 (diff)
downloadbugzilla-946aa2272f2789fbdae896d8534cb18d9df75129.tar.gz
bugzilla-946aa2272f2789fbdae896d8534cb18d9df75129.tar.xz
Bug 286689: Cross-DB bz_add_index and bz_drop_index (Part of Bug 285111)
Patch By Max Kanat-Alexander <mkanat@kerio.com> r=Tomas.Kopal, a=justdave
Diffstat (limited to 'Bugzilla/DB.pm')
-rw-r--r--Bugzilla/DB.pm56
1 files changed, 56 insertions, 0 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index 292925a6f..2168e6ae4 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -392,6 +392,23 @@ sub bz_add_field ($$$) {
ADD COLUMN $field $definition");
}
+sub bz_add_index {
+ my ($self, $table, $name, $definition) = @_;
+
+ 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_real_schema->set_index($table, $name, $definition);
+ $self->_bz_store_real_schema;
+ }
+}
+
# XXX - Need to make this cross-db compatible
# XXX - This shouldn't print stuff to stdout
sub bz_change_field_type ($$$) {
@@ -430,6 +447,23 @@ sub bz_drop_field ($$) {
DROP COLUMN $field");
}
+sub bz_drop_index {
+ my ($self, $table, $name) = @_;
+
+ 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_real_schema->delete_index($table, $name);
+ $self->_bz_store_real_schema;
+ }
+}
+
# XXX - Needs to be made cross-db compatible
sub bz_drop_table_indexes ($) {
my ($self, $table) = @_;
@@ -778,6 +812,8 @@ Bugzilla::DB - Database access routines, using L<DBI>
# Schema Modification
$dbh->bz_add_column($table, $name, \%definition);
+ $dbh->bz_add_index($table, $name, $definition);
+ $dbh->bz_drop_index($table, $name);
# Schema Modification (DEPRECATED)
$dbh->bz_add_field($table, $column, $definition);
@@ -1097,6 +1133,26 @@ C<Bugzilla::DB::Schema::ABSTRACT_SCHEMA>.
\%definition = Abstract column definition for the new column
Returns: nothing
+=item C<bz_add_index($table, $name, $definition)>
+
+ Description: Adds a new index to a table in the database. Prints
+ out a brief statement that it did so, to stdout.
+ If the index already exists, we will do nothing.
+ Params: $table - The table the new index is on.
+ $name - A name for the new index.
+ $definition - An abstract index definition.
+ Either a hashref or an arrayref.
+ Returns: nothing
+
+=item C<bz_drop_index($table, $name)>
+
+ Description: Removes an index from the database. Prints out a brief
+ statement that it did so, to stdout. If the index
+ doesn't exist, we do nothing.
+ Params: $table - The table that the index is on.
+ $name - The name of the index that you want to drop.
+ Returns: nothing
+
=back