diff options
author | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-07-15 00:30:39 +0200 |
---|---|---|
committer | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-07-15 00:30:39 +0200 |
commit | e6ea9c3931636f5ebfb7877da18af28b221cdc58 (patch) | |
tree | 83537fc05c09d7480aeea0c5e21aeaeeab4c4f63 /Bugzilla/DB | |
parent | 0fd1b7d50b118d6f1ddaebce987e9cbd9748efa7 (diff) | |
download | bugzilla-e6ea9c3931636f5ebfb7877da18af28b221cdc58.tar.gz bugzilla-e6ea9c3931636f5ebfb7877da18af28b221cdc58.tar.xz |
Bug 578739: Instead of removing REFERENCES from _bz_real_schema and then
populating FKs from _bz_schema at the end of checksetup, store REFERENCES
in _bz_real_schema with a special "created => 0" key that tells us that
we still need to create the FK.
r=mkanat, a=mkanat (module owner)
Diffstat (limited to 'Bugzilla/DB')
-rw-r--r-- | Bugzilla/DB/Mysql.pm | 10 | ||||
-rw-r--r-- | Bugzilla/DB/Oracle.pm | 2 | ||||
-rw-r--r-- | Bugzilla/DB/Schema.pm | 48 |
3 files changed, 47 insertions, 13 deletions
diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm index 66a261c75..699fcfdf6 100644 --- a/Bugzilla/DB/Mysql.pm +++ b/Bugzilla/DB/Mysql.pm @@ -721,7 +721,6 @@ EOT print "Converting table storage format to UTF-8. This may take a", " while.\n"; - my @dropped_fks; foreach my $table ($self->bz_table_list_real) { my $info_sth = $self->prepare("SHOW FULL COLUMNS FROM $table"); $info_sth->execute(); @@ -740,8 +739,9 @@ EOT print "$table.$name needs to be converted to UTF-8...\n"; - my $dropped = $self->bz_drop_related_fks($table, $name); - push(@dropped_fks, @$dropped); + # These will be automatically re-created at the end + # of checksetup. + $self->bz_drop_related_fks($table, $name); my $col_info = $self->bz_column_info_real($table, $name); @@ -792,10 +792,6 @@ EOT } } # foreach my $table (@tables) - - foreach my $fk_args (@dropped_fks) { - $self->bz_add_fk(@$fk_args); - } } # Sometimes you can have a situation where all the tables are utf8, diff --git a/Bugzilla/DB/Oracle.pm b/Bugzilla/DB/Oracle.pm index 0819bd19a..a7ac6e93e 100644 --- a/Bugzilla/DB/Oracle.pm +++ b/Bugzilla/DB/Oracle.pm @@ -247,7 +247,7 @@ sub bz_drop_table { # Dropping all FKs for a specified table. sub _bz_drop_fks { my ($self, $table) = @_; - my @columns = $self->_bz_real_schema->get_table_columns($table); + my @columns = $self->bz_table_columns($table); foreach my $column (@columns) { $self->bz_drop_fk($table, $column); } diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 4837ccc5f..a00a7b9d9 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -44,12 +44,12 @@ use Bugzilla::Constants; use Carp qw(confess); use Digest::MD5 qw(md5_hex); use Hash::Util qw(lock_value unlock_hash lock_keys unlock_keys); -use List::MoreUtils qw(firstidx); +use List::MoreUtils qw(firstidx natatime); use Safe; # Historical, needed for SCHEMA_VERSION = '1.00' use Storable qw(dclone freeze thaw); -# New SCHEMA_VERSION (2.00) use this +# New SCHEMA_VERSIONs (2+) use this use Data::Dumper; =head1 NAME @@ -208,7 +208,7 @@ update this column in this table." =cut -use constant SCHEMA_VERSION => '2.00'; +use constant SCHEMA_VERSION => 3; use constant ADD_COLUMN => 'ADD COLUMN'; # Multiple FKs can be added using ALTER TABLE ADD CONSTRAINT in one # SQL statement. This isn't true for all databases. @@ -2545,6 +2545,28 @@ sub set_column { $self->_set_object($table, $column, $new_def, $fields); } +=item C<set_fk($table, $column \%fk_def)> + +Sets the C<REFERENCES> item on the specified column. + +=cut + +sub set_fk { + my ($self, $table, $column, $fk_def) = @_; + # Don't want to modify the source def before we explicitly set it below. + # This is just us being extra-cautious. + my $column_def = dclone($self->get_column_abstract($table, $column)); + die "Tried to set an fk on $table.$column, but that column doesn't exist" + if !$column_def; + if ($fk_def) { + $column_def->{REFERENCES} = $fk_def; + } + else { + delete $column_def->{REFERENCES}; + } + $self->set_column($table, $column, $column_def); +} + sub set_index { =item C<set_index($table, $name, $definition)> @@ -2697,7 +2719,7 @@ sub serialize_abstract { Description: Used for when you've read a serialized Schema off the disk, and you want a Schema object that represents that data. Params: $serialized - scalar. The serialized data. - $version - A number in the format X.YZ. The "version" + $version - A number. The "version" of the Schema that did the serialization. See the docs for C<SCHEMA_VERSION> for more details. Returns: A Schema object. It will have the methods of (and work @@ -2710,7 +2732,7 @@ sub deserialize_abstract { my ($class, $serialized, $version) = @_; my $thawed_hash; - if (int($version) < 2) { + if ($version < 2) { $thawed_hash = thaw($serialized); } else { @@ -2720,6 +2742,22 @@ sub deserialize_abstract { $thawed_hash = ${$cpt->varglob('VAR1')}; } + # Version 2 didn't have the "created" key for REFERENCES items. + if ($version < 3) { + my $standard = $class->new()->{abstract_schema}; + foreach my $table_name (keys %$thawed_hash) { + my %standard_fields = + @{ $standard->{$table_name}->{FIELDS} || [] }; + my $table = $thawed_hash->{$table_name}; + my %fields = @{ $table->{FIELDS} || [] }; + while (my ($field, $def) = each %fields) { + if (exists $def->{REFERENCES}) { + $def->{REFERENCES}->{created} = 1; + } + } + } + } + return $class->new(undef, $thawed_hash); } |