Move more normalization changes to preprocess_schema
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / MySQL.pm
index 6c20e56..1252f89 100644 (file)
@@ -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'";