Move more normalization changes to preprocess_schema
Ash Berlin [Thu, 10 Jan 2008 15:12:57 +0000 (15:12 +0000)]
lib/SQL/Translator/Producer/MySQL.pm
t/16xml-parser.t

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'";
index b7fcb78..05c9ad8 100644 (file)
@@ -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",