From: Jaime Soriano Pastor Date: Wed, 21 Dec 2011 17:16:00 +0000 (+0100) Subject: Name of unique keys are not written if empty X-Git-Tag: v0.11011~57 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=55da13f2dbe7af0c51881fa5a9b39506a0ffbe58;p=dbsrgits%2FSQL-Translator.git Name of unique keys are not written if empty --- diff --git a/Changes b/Changes index a4d69d4..0f5a895 100644 --- a/Changes +++ b/Changes @@ -14,6 +14,7 @@ * Check in MySQL parser to avoid trying to parse a table defined twice in the same file as indices (and probably other things) get messed up * Workaround for some MySQL quirks on primary key definitions +* MySQL producer does not attempt to write out non-existent unique constraint names # ---------------------------------------------------------- # 0.11010 2011-10-05 diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index 7e10d55..bd53796 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -731,10 +731,18 @@ sub create_constraint return 'PRIMARY KEY (' . $qf . join("$qf, $qf", @fields). $qf . ')'; } elsif ( $c->type eq UNIQUE ) { - return - 'UNIQUE '. - (defined $c->name ? $qf.truncate_id_uniquely( $c->name, $options->{max_id_length} || $DEFAULT_MAX_ID_LENGTH ).$qf.' ' : ''). - '(' . $qf . join("$qf, $qf", @fields). $qf . ')'; + return sprintf 'UNIQUE %s(%s)', + ((defined $c->name && $c->name) + ? join ('', + $qf, + truncate_id_uniquely( $c->name, $options->{max_id_length} || $DEFAULT_MAX_ID_LENGTH ), + $qf, + ' ' + ) + : '' + ), + ( join ', ', map { "${qf}${_}${qf}" } @fields ), + ; } elsif ( $c->type eq FOREIGN_KEY ) { #