Commit f53d4eac authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 284348: Move initial table creation into the Bugzilla::DB modules

Patch By Max Kanat-Alexander <mkanat@kerio.com> r=glob, r=Tomas.Kopal, a=justdave
parent 64dcdcd3
......@@ -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
......
......@@ -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;
......@@ -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) = @_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment