summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Schema.pm
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-04-17 16:22:41 +0200
committermkanat%kerio.com <>2005-04-17 16:22:41 +0200
commit77691d57c478404d33235d45cb94156efd3a95f2 (patch)
tree7f9fb1b32bd9d7320849d89ecfbffbe243f0d33d /Bugzilla/DB/Schema.pm
parent2d313bda0114f1f61ba2aff76d5505ec48f57f75 (diff)
downloadbugzilla-77691d57c478404d33235d45cb94156efd3a95f2.tar.gz
bugzilla-77691d57c478404d33235d45cb94156efd3a95f2.tar.xz
Bug 290402: Functions to support reading-in a Schema object from the database
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=justdave
Diffstat (limited to 'Bugzilla/DB/Schema.pm')
-rw-r--r--Bugzilla/DB/Schema.pm84
1 files changed, 79 insertions, 5 deletions
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm
index b151edf91..c65d1f0f2 100644
--- a/Bugzilla/DB/Schema.pm
+++ b/Bugzilla/DB/Schema.pm
@@ -897,7 +897,8 @@ use constant ABSTRACT_SCHEMA => {
whine_queries => {
FIELDS => [
- id => {TYPE => 'MEDIUMSERIAL', PRIMARYKEY => 1},
+ id => {TYPE => 'MEDIUMSERIAL', PRIMARYKEY => 1,
+ NOTNULL => 1},
eventid => {TYPE => 'INT3', NOTNULL => 1},
query_name => {TYPE => 'varchar(64)', NOTNULL => 1,
DEFAULT => "''"},
@@ -914,7 +915,8 @@ use constant ABSTRACT_SCHEMA => {
whine_schedules => {
FIELDS => [
- id => {TYPE => 'MEDIUMSERIAL', PRIMARYKEY => 1},
+ id => {TYPE => 'MEDIUMSERIAL', PRIMARYKEY => 1,
+ NOTNULL => 1},
eventid => {TYPE => 'INT3', NOTNULL => 1},
run_day => {TYPE => 'varchar(32)'},
run_time => {TYPE => 'varchar(32)'},
@@ -930,7 +932,8 @@ use constant ABSTRACT_SCHEMA => {
whine_events => {
FIELDS => [
- id => {TYPE => 'MEDIUMSERIAL', PRIMARYKEY => 1},
+ id => {TYPE => 'MEDIUMSERIAL', PRIMARYKEY => 1,
+ NOTNULL => 1},
owner_userid => {TYPE => 'INT3', NOTNULL => 1},
subject => {TYPE => 'varchar(128)'},
body => {TYPE => 'MEDIUMTEXT'},
@@ -1211,7 +1214,7 @@ sub get_column {
}
return undef;
} #eosub--get_column
-#--------------------------------------------------------------------------
+
sub get_table_list {
=item C<get_table_list>
@@ -1584,7 +1587,7 @@ sub get_column_abstract {
# Prevent a possible dereferencing of an undef hash, if the
# table doesn't exist.
- if (exists $self->{abstract_schema}->{$table}) {
+ if ($self->get_table_abstract($table)) {
my %fields = (@{ $self->{abstract_schema}{$table}{FIELDS} });
return $fields{$column};
}
@@ -1616,6 +1619,47 @@ sub get_index_abstract {
return undef;
}
+=item C<get_table_abstract($table)>
+
+ Description: Gets the abstract definition for a table in this Schema
+ object.
+ Params: $table - The name of the table you want a definition for.
+ Returns: An abstract table definition, or undef if the table doesn't
+ exist.
+
+=cut
+
+sub get_table_abstract {
+ my ($self, $table) = @_;
+ return $self->{abstract_schema}->{$table};
+}
+
+=item C<add_table($name, \%definition)>
+
+ Description: Creates a new table in this Schema object.
+ If you do not specify a definition, we will
+ simply create an empty table.
+ Params: $name - The name for the new table.
+ \%definition (optional) - An abstract definition for
+ the new table.
+ Returns: nothing
+
+=cut
+sub add_table {
+ my ($self, $name, $definition) = @_;
+ (die "Table already exists: $name")
+ if exists $self->{abstract_schema}->{$name};
+ if ($definition) {
+ $self->{abstract_schema}->{$name} = dclone($definition);
+ $self->{schema} = dclone($self->{abstract_schema});
+ $self->_adjust_schema();
+ }
+ else {
+ $self->{abstract_schema}->{$name} = {FIELDS => []};
+ $self->{schema}->{$name} = {FIELDS => []};
+ }
+}
+
sub delete_column {
=item C<delete_column($table, $column)>
@@ -1705,6 +1749,11 @@ sub set_index {
my ($self, $table, $name, $definition) = @_;
+ if ( exists $self->{abstract_schema}{$table}
+ && !exists $self->{abstract_schema}{$table}{INDEXES} ) {
+ $self->{abstract_schema}{$table}{INDEXES} = [];
+ }
+
my $indexes = $self->{abstract_schema}{$table}{INDEXES};
$self->_set_object($table, $name, $definition, $indexes);
}
@@ -1839,6 +1888,31 @@ sub deserialize_abstract {
return $class->new(undef, $thawed_hash);
}
+#####################################################################
+# Class Methods
+#####################################################################
+
+=back
+
+=head1 CLASS METHODS
+
+These methods are generally called on the class instead of on a specific
+object.
+
+=item C<get_empty_schema()>
+
+ Description: Returns a Schema that has no tables. In effect, this
+ Schema is totally "empty."
+ Params: none
+ Returns: A "empty" Schema object.
+
+=cut
+
+sub get_empty_schema {
+ my ($class) = @_;
+ return $class->deserialize_abstract(freeze({}));
+}
+
1;
__END__