summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Schema/Pg.pm
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-04-15 11:31:35 +0200
committermkanat%kerio.com <>2005-04-15 11:31:35 +0200
commit7be1f1c90805dc6c1845434fc215f9f07199db75 (patch)
tree300ef71ea7c797362fb4ec02794db617ec2b0eb9 /Bugzilla/DB/Schema/Pg.pm
parent6b2e132ec32b657e8f806eedc4d9f06fc66131ef (diff)
downloadbugzilla-7be1f1c90805dc6c1845434fc215f9f07199db75.tar.gz
bugzilla-7be1f1c90805dc6c1845434fc215f9f07199db75.tar.xz
Bug 290405: bz_add_column needs a way to specify an initial value
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=justdave
Diffstat (limited to 'Bugzilla/DB/Schema/Pg.pm')
-rw-r--r--Bugzilla/DB/Schema/Pg.pm10
1 files changed, 7 insertions, 3 deletions
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");