From: Ash Berlin Date: Thu, 10 Jan 2008 15:12:57 +0000 (+0000) Subject: Move more normalization changes to preprocess_schema X-Git-Tag: v0.11008~348^2~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Translator.git;a=commitdiff_plain;h=929ef2654458a8895cfe678530592e12b5f78ad7 Move more normalization changes to preprocess_schema --- diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index 6c20e56..1252f89 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -178,7 +178,7 @@ sub preprocess_schema { $mysql_table_type_to_options->($table); - foreach my $c( $table->get_constraints ) { + foreach my $c ( $table->get_constraints ) { next unless $c->type eq FOREIGN_KEY; # Normalize constraint names here. @@ -194,7 +194,15 @@ sub preprocess_schema { next if $mysql_table_type_to_options->($table); $table->options( { 'ENGINE' => 'InnoDB' } ); } + } # foreach constraints + + foreach my $f ( $table->get_fields ) { + my @size = $f->size; + if ( !$size[0] && $f->data_type =~ /char$/ ) { + $f->size( (255) ); + } } + } } @@ -379,9 +387,6 @@ sub create_field $data_type = 'text'; @size = (); } - elsif ( $data_type =~ /char/i && ! $size[0] ) { - @size = (255); - } elsif ( $data_type =~ /boolean/i ) { $data_type = 'enum'; $commalist = "'0','1'"; diff --git a/t/16xml-parser.t b/t/16xml-parser.t index b7fcb78..05c9ad8 100644 --- a/t/16xml-parser.t +++ b/t/16xml-parser.t @@ -105,12 +105,14 @@ schema_ok( $scma, { data_type => "varchar", default_value => undef, is_nullable => 1, + size => 255, }, { name => "explicitemptystring", data_type => "varchar", default_value => "", is_nullable => 1, + size => 255, }, { name => "emptytagdef", @@ -118,6 +120,7 @@ schema_ok( $scma, { default_value => "", is_nullable => 1, comments => "Hello emptytagdef", + size => 255, }, { name => "another_id",