summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Schema.pm
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/Schema.pm
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/Schema.pm')
-rw-r--r--Bugzilla/DB/Schema.pm22
1 files changed, 17 insertions, 5 deletions
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"