summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Schema/Pg.pm
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-04-05 06:30:15 +0200
committermkanat%kerio.com <>2005-04-05 06:30:15 +0200
commitadf5bbdb40ef7695a33ec9ca4565182a99b83dea (patch)
treeab02a5587d1fd151136e8806a3aa2c239f954f3a /Bugzilla/DB/Schema/Pg.pm
parent9642abb3e0215cc795478c3713ab1ef1eadcb770 (diff)
downloadbugzilla-adf5bbdb40ef7695a33ec9ca4565182a99b83dea.tar.gz
bugzilla-adf5bbdb40ef7695a33ec9ca4565182a99b83dea.tar.xz
Bug 286527: Cross-DB bz_rename_column and bz_drop_column (Part of Bug 285111)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=myk
Diffstat (limited to 'Bugzilla/DB/Schema/Pg.pm')
-rw-r--r--Bugzilla/DB/Schema/Pg.pm17
1 files changed, 15 insertions, 2 deletions
diff --git a/Bugzilla/DB/Schema/Pg.pm b/Bugzilla/DB/Schema/Pg.pm
index 59072e79d..d88bc520c 100644
--- a/Bugzilla/DB/Schema/Pg.pm
+++ b/Bugzilla/DB/Schema/Pg.pm
@@ -101,15 +101,22 @@ sub get_add_column_ddl {
push(@statements, "ALTER TABLE $table ADD COLUMN $column $type");
my $default = $definition->{DEFAULT};
- # Replace any abstract default value (such as 'TRUE' or 'FALSE')
- # with its database-specific implementation.
if (defined $default) {
+ # Replace any abstract default value (such as 'TRUE' or 'FALSE')
+ # with its database-specific implementation.
$default = $specific->{$default} if exists $specific->{$default};
push(@statements, "ALTER TABLE $table ALTER COLUMN $column "
. " SET DEFAULT $default");
}
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};
+ push(@statements, "UPDATE $table SET $column = $default");
push(@statements, "ALTER TABLE $table ALTER COLUMN $column "
. " SET NOT NULL");
}
@@ -122,4 +129,10 @@ sub get_add_column_ddl {
return @statements;
}
+sub get_rename_column_ddl {
+ my ($self, $table, $old_name, $new_name) = @_;
+
+ return ("ALTER TABLE $table RENAME COLUMN $old_name TO $new_name");
+}
+
1;