summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/DB.pm48
-rw-r--r--Bugzilla/DB/Mysql.pm36
-rw-r--r--Bugzilla/DB/Pg.pm3
3 files changed, 81 insertions, 6 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index 1dccf535a..59d19b48b 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -48,6 +48,7 @@ Exporter::export_ok_tags('deprecated');
use Bugzilla::Config qw(:DEFAULT :db);
use Bugzilla::Util;
use Bugzilla::Error;
+use Bugzilla::DB::Schema;
# All this code is backwards compat fu. As such, its a bit ugly. Note the
# circular dependencies on Bugzilla.pm
@@ -277,6 +278,31 @@ sub bz_get_field_defs {
}
#####################################################################
+# Database Setup
+#####################################################################
+
+sub bz_setup_database {
+ my ($self) = @_;
+
+ # Get a list of the existing tables (if any) in the database
+ my $table_sth = $self->table_info(undef, undef, undef, "TABLE");
+ my @current_tables =
+ @{$self->selectcol_arrayref($table_sth, { Columns => [3] })};
+
+ my @desired_tables = $self->_bz_schema->get_table_list();
+
+ foreach my $table_name (@desired_tables) {
+ next if grep /^$table_name$/, @current_tables;
+ print "Creating table $table_name ...\n";
+
+ my @table_sql = $self->_bz_schema->get_table_ddl($table_name);
+ foreach my $sql_statement (@table_sql) {
+ $self->do($sql_statement);
+ }
+ }
+}
+
+#####################################################################
# Schema Modification Methods
#####################################################################
@@ -383,6 +409,14 @@ sub bz_rename_field ($$$) {
# Schema Information Methods
#####################################################################
+sub _bz_schema {
+ my ($self) = @_;
+ return $self->{private_bz_schema} if exists $self->{private_bz_schema};
+ $self->{private_bz_schema} =
+ Bugzilla::DB::Schema->new($self->MODULE_NAME);
+ return $self->{private_bz_schema};
+}
+
# XXX - Needs to be made cross-db compatible.
sub bz_get_field_def ($$) {
my ($self, $table, $field) = @_;
@@ -417,7 +451,7 @@ sub bz_get_index_def ($$) {
$sth->execute;
while (my $ref = $sth->fetchrow_arrayref) {
- next if $$ref[2] ne $field;
+ next if $$ref[4] ne $field;
return $ref;
}
}
@@ -449,7 +483,6 @@ sub bz_start_transaction {
} else {
# Turn AutoCommit off and start a new transaction
$self->begin_work();
-
$self->{privateprivate_bz_in_transaction} = 1;
}
}
@@ -557,7 +590,7 @@ Bugzilla::DB - Database access routines, using L<DBI>
# Schema Information
my @fields = $dbh->bz_get_field_defs();
my @fieldinfo = $dbh->bz_get_field_def($table, $column);
- my @indexinfo = $dbh->bz_get_index_def($table, $index);
+ my @indexinfo = $dbh->bz_get_index_def($table, $field);
my $exists = $dbh->bz_table_exists($table);
=head1 DESCRIPTION
@@ -595,6 +628,11 @@ would be 'MySQL.' You should not depend on this variable to know what
type of database you are running on; this is intended merely for displaying
to the admin to let them know what DB they're running.
+=item C<MODULE_NAME>
+
+The name of the Bugzilla::DB module that we are. For example, for the MySQL
+Bugzilla::DB module, this would be "Mysql." For PostgreSQL it would be "Pg."
+
=head1 CONNECTION
A new database handle to the required database can be created using this
@@ -898,11 +936,11 @@ These methods return info about the current Bugzilla database schema.
Params: $table = the table that you want to count indexes on
Returns: The number of indexes on the table.
-=item C<bz_get_index_def>
+=item C<bz_get_index_def($table, $field)>
Description: Returns information about an index on a table in the database.
Params: $table = name of table containing the index (scalar)
- $index = name of the index (scalar)
+ $field = name of a field that the index is on (scalar)
Returns: A reference to an array containing information about the
index, with the following information in each array place:
0 = name of the table that the index is on
diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm
index 76cd0966d..14230b188 100644
--- a/Bugzilla/DB/Mysql.pm
+++ b/Bugzilla/DB/Mysql.pm
@@ -49,6 +49,7 @@ use base qw(Bugzilla::DB);
use constant REQUIRED_VERSION => '3.23.41';
use constant PROGRAM_NAME => 'MySQL';
+use constant MODULE_NAME => 'Mysql';
sub new {
my ($class, $user, $pass, $host, $dbname, $port, $sock) = @_;
@@ -189,4 +190,39 @@ sub bz_rollback_transaction {
die("Attempt to rollback transaction on DB without transaction support");
}
+#####################################################################
+# Database Setup
+#####################################################################
+
+sub bz_setup_database {
+ my ($self) = @_;
+
+ # Figure out if any existing tables are of type ISAM and convert them
+ # to type MyISAM if so. ISAM tables are deprecated in MySQL 3.23,
+ # which Bugzilla now requires, and they don't support more than 16
+ # indexes per table, which Bugzilla needs.
+ my $sth = $self->prepare("SHOW TABLE STATUS");
+ $sth->execute;
+ my @isam_tables = ();
+ while (my ($name, $type) = $sth->fetchrow_array) {
+ push(@isam_tables, $name) if $type eq "ISAM";
+ }
+
+ if(scalar(@isam_tables)) {
+ print "One or more of the tables in your existing MySQL database are\n"
+ . "of type ISAM. ISAM tables are deprecated in MySQL 3.23 and\n"
+ . "don't support more than 16 indexes per table, which \n"
+ . "Bugzilla needs.\n Converting your ISAM tables to type"
+ . " MyISAM:\n\n";
+ foreach my $table (@isam_tables) {
+ print "Converting table $table... ";
+ $self->do("ALTER TABLE $table TYPE = MYISAM");
+ print "done.\n";
+ }
+ print "\nISAM->MyISAM table conversion done.\n\n";
+ }
+
+ $self->SUPER::bz_setup_database();
+}
+
1;
diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm
index 5963f5308..2ec3000d5 100644
--- a/Bugzilla/DB/Pg.pm
+++ b/Bugzilla/DB/Pg.pm
@@ -47,8 +47,9 @@ use Carp;
# This module extends the DB interface via inheritance
use base qw(Bugzilla::DB);
-use constant REQUIRED_VERSION => '7.02.0000';
+use constant REQUIRED_VERSION => '7.03.0000';
use constant PROGRAM_NAME => 'PostgreSQL';
+use constant MODULE_NAME => 'Pg';
sub new {
my ($class, $user, $pass, $host, $dbname, $port) = @_;