From 7be1f1c90805dc6c1845434fc215f9f07199db75 Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Fri, 15 Apr 2005 09:31:35 +0000 Subject: Bug 290405: bz_add_column needs a way to specify an initial value Patch By Max Kanat-Alexander r=Tomas.Kopal, a=justdave --- Bugzilla/DB/Schema/Pg.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Bugzilla/DB/Schema') diff --git a/Bugzilla/DB/Schema/Pg.pm b/Bugzilla/DB/Schema/Pg.pm index d88bc520c..14c98308a 100644 --- a/Bugzilla/DB/Schema/Pg.pm +++ b/Bugzilla/DB/Schema/Pg.pm @@ -91,7 +91,7 @@ sub _initialize { # Overridden because Pg has such weird ALTER TABLE problems. sub get_add_column_ddl { - my ($self, $table, $column, $definition) = @_; + my ($self, $table, $column, $definition, $init_value) = @_; my @statements; my $specific = $self->{db_specific}; @@ -109,13 +109,17 @@ sub get_add_column_ddl { . " SET DEFAULT $default"); } + if (defined $init_value) { + push(@statements, "UPDATE $table SET $column = $init_value"); + } + if ($definition->{NOTNULL}) { # Handle rows that were NULL when we added the column. # We *must* have a DEFAULT. This check is usually handled # at a higher level than this code, but I figure it can't # hurt to have it here. - die "NOT NULL columns must have a DEFAULT" - unless exists $definition->{DEFAULT}; + die "NOT NULL columns must have a DEFAULT or an init_value." + unless (exists $definition->{DEFAULT} || defined $init_value); push(@statements, "UPDATE $table SET $column = $default"); push(@statements, "ALTER TABLE $table ALTER COLUMN $column " . " SET NOT NULL"); -- cgit v1.2.3-24-g4f1b