summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Schema
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
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')
-rw-r--r--Bugzilla/DB/Schema/Mysql.pm9
-rw-r--r--Bugzilla/DB/Schema/Pg.pm17
2 files changed, 21 insertions, 5 deletions
diff --git a/Bugzilla/DB/Schema/Mysql.pm b/Bugzilla/DB/Schema/Mysql.pm
index 6340998b7..07d7036e4 100644
--- a/Bugzilla/DB/Schema/Mysql.pm
+++ b/Bugzilla/DB/Schema/Mysql.pm
@@ -100,11 +100,8 @@ 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 $new_ddl = $self->get_type_ddl($new_def);
-
return (("ALTER TABLE $table CHANGE COLUMN $column $column $new_ddl"));
}
@@ -113,4 +110,10 @@ sub get_drop_index_ddl {
return ("DROP INDEX $name ON $table");
}
+sub get_rename_column_ddl {
+ my ($self, $table, $old_name, $new_name) = @_;
+ my $def = $self->get_type_ddl($self->get_column($table, $old_name));
+ return ("ALTER TABLE $table CHANGE COLUMN $old_name $new_name $def");
+}
+
1;
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;