summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB.pm
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-04-23 11:11:51 +0200
committermkanat%kerio.com <>2005-04-23 11:11:51 +0200
commitcc8d6d3943c9c3cf82e6b1e13c1479a0cef77554 (patch)
tree3c08e212a93c636cfe96753f17b6b42dada291b6 /Bugzilla/DB.pm
parent372be50dde891c803392ed565ba93d5f61190394 (diff)
downloadbugzilla-cc8d6d3943c9c3cf82e6b1e13c1479a0cef77554.tar.gz
bugzilla-cc8d6d3943c9c3cf82e6b1e13c1479a0cef77554.tar.xz
Bug 287986: Bugzilla::DB::Mysql needs a way to read in a Schema object from the disk
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=justdave
Diffstat (limited to 'Bugzilla/DB.pm')
-rw-r--r--Bugzilla/DB.pm56
1 files changed, 35 insertions, 21 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index b6025791f..850ea683a 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -304,26 +304,15 @@ sub bz_get_field_defs {
sub bz_setup_database {
my ($self) = @_;
- # Get a list of the existing tables (if any) in the database
- my @current_tables = $self->bz_table_list_real();
+ # If we haven't ever stored a serialized schema,
+ # set up the bz_schema table and store it.
+ $self->_bz_init_schema_storage();
+
my @desired_tables = $self->_bz_schema->get_table_list();
foreach my $table_name (@desired_tables) {
- next if grep($_ eq $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);
- }
+ $self->bz_add_table($table_name);
}
-
- # And now, if we haven't already stored the serialized schema,
- # store the ABSTRACT_SCHEMA from Bugzilla::DB::Schema.
- # XXX - The code is not ready for this yet, but once
- # all the deps of bug 285111 are checked-in and
- # tested, this should be uncommented.
- #$self->_bz_init_schema_storage();
}
#####################################################################
@@ -775,17 +764,42 @@ These methods really are private. Do not override them in subclasses.
sub _bz_init_schema_storage {
my ($self) = @_;
- my $table_size = $self->selectrow_array("SELECT COUNT(*) FROM bz_schema");
+ my $table_size;
+ eval {
+ $table_size =
+ $self->selectrow_array("SELECT COUNT(*) FROM bz_schema");
+ };
+
+ if (!$table_size) {
+ my $init_schema = $self->_bz_get_initial_schema;
+ my $store_me = $init_schema->serialize_abstract();
+ my $schema_version = $init_schema->SCHEMA_VERSION;
+
+ # If table_size is not defined, then we hit an error reading the
+ # bz_schema table, which means it probably doesn't exist yet. So,
+ # we have to create it. If we failed above for some other reason,
+ # we'll see the failure here.
+ # However, we must create the table after we do get_initial_schema,
+ # because some versions of get_initial_schema read that the table
+ # exists and then add it to the Schema, where other versions don't.
+ if (!defined $table_size) {
+ $self->_bz_add_table_raw('bz_schema');
+ }
- if ($table_size == 0) {
print "Initializing the new Schema storage...\n";
- my $store_me = $self->_bz_schema->serialize_abstract();
- my $schema_version = $self->_bz_schema->SCHEMA_VERSION;
my $sth = $self->prepare("INSERT INTO bz_schema "
." (schema_data, version) VALUES (?,?)");
$sth->bind_param(1, $store_me, $self->BLOB_TYPE);
- $sth->bind_param(2, Bugzilla::DB::Schema::SCHEMA_VERSION);
+ $sth->bind_param(2, $schema_version);
$sth->execute();
+
+ # And now we have to update the on-disk schema to hold the bz_schema
+ # table, if the bz_schema table didn't exist when we were called.
+ if (!defined $table_size) {
+ $self->_bz_real_schema->add_table('bz_schema',
+ $self->_bz_schema->get_table_abstract('bz_schema'));
+ $self->_bz_store_real_schema;
+ }
}
# Sanity check
elsif ($table_size > 1) {