summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-12-19 03:53:00 +0100
committermkanat%kerio.com <>2005-12-19 03:53:00 +0100
commit70adf1be30d18f1735a14813abccdc79baca0e4b (patch)
tree40f1ed65b83b81842f967995c0b5a6e14c57f715 /Bugzilla/DB
parent8b20187ddffa6ee49d5bf51cb35a5a5db0364e44 (diff)
downloadbugzilla-70adf1be30d18f1735a14813abccdc79baca0e4b.tar.gz
bugzilla-70adf1be30d18f1735a14813abccdc79baca0e4b.tar.xz
Bug 310231: MySQL-specific get_alter_column_ddl will not drop primary key
Patch By Olav Vitters <bugzilla-mozilla@bkor.dhs.org> r=mkanat, a=justdave
Diffstat (limited to 'Bugzilla/DB')
-rw-r--r--Bugzilla/DB/Schema/Mysql.pm15
1 files changed, 14 insertions, 1 deletions
diff --git a/Bugzilla/DB/Schema/Mysql.pm b/Bugzilla/DB/Schema/Mysql.pm
index ba6ac7280..04ea92162 100644
--- a/Bugzilla/DB/Schema/Mysql.pm
+++ b/Bugzilla/DB/Schema/Mysql.pm
@@ -153,12 +153,25 @@ 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, $set_nulls_to) = @_;
- my $new_ddl = $self->get_type_ddl($new_def);
+ my $old_def = $self->get_column($table, $column);
+ my %new_def_copy = %$new_def;
+ if ($old_def->{PRIMARYKEY} && $new_def->{PRIMARYKEY}) {
+ # If a column stays a primary key do NOT specify PRIMARY KEY in the
+ # ALTER TABLE statement. This avoids a MySQL error that two primary
+ # keys are not allowed.
+ delete $new_def_copy{PRIMARYKEY};
+ }
+
+ my $new_ddl = $self->get_type_ddl(\%new_def_copy);
my @statements;
push(@statements, "UPDATE $table SET $column = $set_nulls_to
WHERE $column IS NULL") if defined $set_nulls_to;
push(@statements, "ALTER TABLE $table CHANGE COLUMN
$column $column $new_ddl");
+ if ($old_def->{PRIMARYKEY} && !$new_def->{PRIMARYKEY}) {
+ # Dropping a PRIMARY KEY needs an explicit DROP PRIMARY KEY
+ push(@statements, "ALTER TABLE $table DROP PRIMARY KEY");
+ }
return @statements;
}