summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-04-23 11:09:22 +0200
committermkanat%kerio.com <>2005-04-23 11:09:22 +0200
commit372be50dde891c803392ed565ba93d5f61190394 (patch)
tree865e4e6f89dda31560f47be5311dc229bdd9bfa8 /Bugzilla/DB
parentc6c829a7f63c7048705d5bf86c60df015993851e (diff)
downloadbugzilla-372be50dde891c803392ed565ba93d5f61190394.tar.gz
bugzilla-372be50dde891c803392ed565ba93d5f61190394.tar.xz
Bug 285722: Updates From 2.18- to 2.20+ will not work
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=justdave
Diffstat (limited to 'Bugzilla/DB')
-rw-r--r--Bugzilla/DB/Mysql.pm31
-rw-r--r--Bugzilla/DB/Schema.pm22
-rw-r--r--Bugzilla/DB/Schema/Mysql.pm11
3 files changed, 44 insertions, 20 deletions
diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm
index 921b27195..08d72e4d3 100644
--- a/Bugzilla/DB/Mysql.pm
+++ b/Bugzilla/DB/Mysql.pm
@@ -359,7 +359,7 @@ sub bz_setup_database {
# Fix the name to fit in with the new naming scheme.
my $new_name = $table . "_" .
$index->{FIELDS}->[0] . "_idx";
- print "Renaming index $column to to $new_name...\n";
+ print "Renaming index $column to $new_name...\n";
# Unfortunately, MySQL has no way to rename an index. :-(
# So we have to drop and recreate the indexes.
$self->bz_drop_index_raw($table, $column, "silent");
@@ -370,6 +370,11 @@ sub bz_setup_database {
} # foreach table
} # if old-name indexes
+
+ # And now we create the tables and the Schema object.
+ $self->SUPER::bz_setup_database();
+
+
# The old timestamp fields need to be adjusted here instead of in
# checksetup. Otherwise the UPDATE statements inside of bz_add_column
# will cause accidental timestamp updates.
@@ -378,8 +383,8 @@ sub bz_setup_database {
# 2002-08-14 - bbaetz@student.usyd.edu.au - bug 153578
# attachments creation time needs to be a datetime, not a timestamp
my $attach_creation =
- $self->bz_get_field_def("attachments", "creation_ts");
- if ($attach_creation && $attach_creation->[1] =~ /^timestamp/) {
+ $self->bz_column_info("attachments", "creation_ts");
+ if ($attach_creation && $attach_creation->{TYPE} =~ /^TIMESTAMP/i) {
print "Fixing creation time on attachments...\n";
my $sth = $self->prepare("SELECT COUNT(attach_id) FROM attachments");
@@ -424,26 +429,26 @@ sub bz_setup_database {
}
print "Done - converted $i attachments\n";
- $self->bz_change_field_type("attachments", "creation_ts",
- 'datetime NOT NULL');
+ $self->bz_alter_column("attachments", "creation_ts",
+ {TYPE => 'DATETIME', NOTNULL => 1});
}
# 2004-08-29 - Tomas.Kopal@altap.cz, bug 257303
# Change logincookies.lastused type from timestamp to datetime
- my $login_lastused = $self->bz_get_field_def("logincookies", "lastused");
- if ($login_lastused && $login_lastused->[1] =~ /^timestamp/) {
- $self->bz_change_field_type('logincookies', 'lastused',
- 'DATETIME NOT NULL');
+ my $login_lastused = $self->bz_column_info("logincookies", "lastused");
+ if ($login_lastused && $login_lastused->{TYPE} =~ /^TIMESTAMP/i) {
+ $self->bz_alter_column('logincookies', 'lastused',
+ { TYPE => 'DATETIME', NOTNULL => 1});
}
# 2005-01-17 - Tomas.Kopal@altap.cz, bug 257315
# Change bugs.delta_ts type from timestamp to datetime
- my $bugs_deltats = $self->bz_get_field_def("bugs", "delta_ts");
- if ($bugs_deltats && $bugs_deltats->[1] =~ /^timestamp/) {
- $self->bz_change_field_type('bugs', 'delta_ts', 'DATETIME NOT NULL');
+ my $bugs_deltats = $self->bz_column_info("bugs", "delta_ts");
+ if ($bugs_deltats && $bugs_deltats->{TYPE} =~ /^TIMESTAMP/i) {
+ $self->bz_alter_column('bugs', 'delta_ts',
+ {TYPE => 'DATETIME', NOTNULL => 1});
}
- $self->SUPER::bz_setup_database();
}
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm
index e0b49d859..a58c20ade 100644
--- a/Bugzilla/DB/Schema.pm
+++ b/Bugzilla/DB/Schema.pm
@@ -1434,11 +1434,16 @@ sub get_alter_column_ddl {
$column - The name of the column being changed.
\%definition - The new definition for the column,
in standard C<ABSTRACT_SCHEMA> format.
+ $set_nulls_to - A value to set NULL values to, if
+ your new definition is NOT NULL and contains
+ no DEFAULT, and when there is a possibility
+ that the column could contain NULLs. $set_nulls_to
+ should be already SQL-quoted if necessary.
Returns: An array of SQL statements.
=cut
- my ($self, $table, $column, $new_def) = @_;
+ my ($self, $table, $column, $new_def, $set_nulls_to) = @_;
my @statements;
my $old_def = $self->get_column_abstract($table, $column);
@@ -1489,10 +1494,17 @@ sub get_alter_column_ddl {
# If we went from NULL to NOT NULL
# OR if we changed the type and we are NOT NULL
if ( (!$old_def->{NOTNULL} && $new_def->{NOTNULL}) ||
- ($typechange && $new_def->{NOTNULL}) ) {
- if (exists $new_def->{DEFAULT}) {
- # Handle any fields that were NULL before, if we have a default.
- push(@statements, "UPDATE $table SET $column = $default"
+ ($typechange && $new_def->{NOTNULL}) )
+ {
+ my $setdefault;
+ # Handle any fields that were NULL before, if we have a default,
+ $setdefault = $new_def->{DEFAULT} if exists $new_def->{DEFAULT};
+ # But if we have a set_nulls_to, that overrides the DEFAULT
+ # (although nobody would usually specify both a default and
+ # a set_nulls_to.)
+ $setdefault = $set_nulls_to if defined $set_nulls_to;
+ if (defined $setdefault) {
+ push(@statements, "UPDATE $table SET $column = $setdefault"
. " WHERE $column IS NULL");
}
push(@statements, "ALTER TABLE $table ALTER COLUMN $column"
diff --git a/Bugzilla/DB/Schema/Mysql.pm b/Bugzilla/DB/Schema/Mysql.pm
index 1ea1d285a..21274f575 100644
--- a/Bugzilla/DB/Schema/Mysql.pm
+++ b/Bugzilla/DB/Schema/Mysql.pm
@@ -151,9 +151,14 @@ sub _get_create_index_ddl {
# MySQL has a simpler ALTER TABLE syntax than ANSI.
sub get_alter_column_ddl {
- my ($self, $table, $column, $new_def) = @_;
+ my ($self, $table, $column, $new_def, $set_nulls_to) = @_;
my $new_ddl = $self->get_type_ddl($new_def);
- return (("ALTER TABLE $table CHANGE COLUMN $column $column $new_ddl"));
+ my @statements;
+ push(@statements, "UPDATE $table SET $column = $set_nulls_to
+ WHERE $column IS NULL") if defined $set_nulls_to;
+ push(@statements, "ALTER TABLE $table CHANGE COLUMN
+ $column $column $new_ddl");
+ return @statements;
}
sub get_drop_index_ddl {
@@ -281,6 +286,8 @@ sub column_info_to_column {
sub get_rename_column_ddl {
my ($self, $table, $old_name, $new_name) = @_;
my $def = $self->get_type_ddl($self->get_column($table, $old_name));
+ # MySQL doesn't like having the PRIMARY KEY statement in a rename.
+ $def =~ s/PRIMARY KEY//i;
return ("ALTER TABLE $table CHANGE COLUMN $old_name $new_name $def");
}