From 8da7f321aabe95470944bc23aeed9a06ef6793a5 Mon Sep 17 00:00:00 2001 From: "justdave%bugzilla.org" <> Date: Sun, 15 Apr 2007 06:35:56 +0000 Subject: Bug 373869: Custom field names must be all lowercase or buglist.cgi sorting throws an error Patch by mkanat and justdave r=LpSolit,mkanat; a=mkanat --- Bugzilla/DB/Schema.pm | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ Bugzilla/DB/Schema/Pg.pm | 15 +++++++++++++++ 2 files changed, 63 insertions(+) (limited to 'Bugzilla/DB') diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 15d7dd8b2..44bda1acb 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -1911,6 +1911,37 @@ sub get_rename_column_ddl { . " has not implemented a method."; } + +sub get_rename_table_sql { + +=item C + +=over + +=item B + +Gets SQL to rename a table in the database. + +=item B + +=over + +=item C<$old_name> - The current name of the table. + +=item C<$new_name> - The new name of the table. + +=back + +=item B: An array of SQL statements to rename a table. + +=back + +=cut + + my ($self, $old_name, $new_name) = @_; + return ("ALTER TABLE $old_name RENAME TO $new_name"); +} + =item C Description: Deletes a table from this Schema object. @@ -2062,6 +2093,23 @@ sub add_table { } } + + +sub rename_table { + +=item C + +Renames a table from C<$old_name> to C<$new_name> in this Schema object. + +=cut + + + my ($self, $old_name, $new_name) = @_; + my $table = $self->get_table_abstract($old_name); + $self->delete_table($old_name); + $self->add_table($new_name, $table); +} + sub delete_column { =item C diff --git a/Bugzilla/DB/Schema/Pg.pm b/Bugzilla/DB/Schema/Pg.pm index 0101a1e43..7a951e2db 100644 --- a/Bugzilla/DB/Schema/Pg.pm +++ b/Bugzilla/DB/Schema/Pg.pm @@ -92,6 +92,11 @@ sub _initialize { sub get_rename_column_ddl { my ($self, $table, $old_name, $new_name) = @_; + if (lc($old_name) eq lc($new_name)) { + # if the only change is a case change, return an empty list, since Pg + # is case-insensitive and will return an error about a duplicate name + return (); + } my @sql = ("ALTER TABLE $table RENAME COLUMN $old_name TO $new_name"); my $def = $self->get_column_abstract($table, $old_name); if ($def->{TYPE} =~ /SERIAL/i) { @@ -104,6 +109,16 @@ sub get_rename_column_ddl { return @sql; } +sub get_rename_table_sql { + my ($self, $old_name, $new_name) = @_; + if (lc($old_name) eq lc($new_name)) { + # if the only change is a case change, return an empty list, since Pg + # is case-insensitive and will return an error about a duplicate name + return (); + } + return ("ALTER TABLE $old_name RENAME TO $new_name"); +} + sub _get_alter_type_sql { my ($self, $table, $column, $new_def, $old_def) = @_; my @statements; -- cgit v1.2.3-24-g4f1b