summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2009-08-03 16:10:50 +0200
committermkanat%bugzilla.org <>2009-08-03 16:10:50 +0200
commit6f4d125ade02836e24101a1e8a4ae40920d176ac (patch)
treed7d6fe6b14b340224d128f5faac387f62a30dd2e /Bugzilla/DB
parente9024051f9835fef0a0ca5223b1ce46098f4a14a (diff)
downloadbugzilla-6f4d125ade02836e24101a1e8a4ae40920d176ac.tar.gz
bugzilla-6f4d125ade02836e24101a1e8a4ae40920d176ac.tar.xz
Bug 508018: Speed up _fix_defaults for MySQL checksetup upgrades
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=mkanat
Diffstat (limited to 'Bugzilla/DB')
-rw-r--r--Bugzilla/DB/Mysql.pm26
1 files changed, 22 insertions, 4 deletions
diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm
index f06900f1b..881ff28b8 100644
--- a/Bugzilla/DB/Mysql.pm
+++ b/Bugzilla/DB/Mysql.pm
@@ -814,22 +814,40 @@ sub _fix_defaults {
# a default.
return unless (defined $assi_default && $assi_default ne '');
+ my %fix_columns;
foreach my $table ($self->_bz_real_schema->get_table_list()) {
foreach my $column ($self->bz_table_columns($table)) {
- my $abs_def = $self->bz_column_info($table, $column);
+ my $abs_def = $self->bz_column_info($table, $column);
+ # BLOB/TEXT columns never have defaults
+ next if $abs_def->{TYPE} =~ /BLOB|TEXT/i;
if (!defined $abs_def->{DEFAULT}) {
# Get the exact default from the database without any
# "fixing" by bz_column_info_real.
my $raw_info = $self->_bz_raw_column_info($table, $column);
my $raw_default = $raw_info->{COLUMN_DEF};
if (defined $raw_default) {
- $self->bz_alter_column_raw($table, $column, $abs_def);
- $raw_default = "''" if $raw_default eq '';
- print "Removed incorrect DB default: $raw_default\n";
+ if ($raw_default eq '') {
+ # Only (var)char columns can have empty strings as
+ # defaults, so if we got an empty string for some
+ # other default type, then it's bogus.
+ next unless $abs_def->{TYPE} =~ /char/i;
+ $raw_default = "''";
+ }
+ $fix_columns{$table} ||= [];
+ push(@{ $fix_columns{$table} }, $column);
+ print "$table.$column has incorrect DB default: $raw_default\n";
}
}
} # foreach $column
} # foreach $table
+
+ print "Fixing defaults...\n";
+ foreach my $table (reverse sort keys %fix_columns) {
+ my @alters = map("ALTER COLUMN $_ DROP DEFAULT",
+ @{ $fix_columns{$table} });
+ my $sql = "ALTER TABLE $table " . join(',', @alters);
+ $self->do($sql);
+ }
}
# There is a bug in MySQL 4.1.0 - 4.1.15 that makes certain SELECT