fix mysql ddl constraint parsing
Justin Hunter [Tue, 25 Aug 2009 05:51:04 +0000 (22:51 -0700)]
lib/SQL/Translator/Parser/DDL/MySQL.pm

index 0a73ac1..a1045e5 100644 (file)
@@ -89,9 +89,6 @@ role SQL::Translator::Parser::DDL::MySQL {
     
                 if ( $fdata->{is_unique} ) {
                     push @{ $tdata->{constraints} }, { name => '', type => 'UNIQUE', fields => [ $fdata->{name} ] };
-#                     my $constraint = Constraint->new({ name => '', type => 'UNIQUE' });
-#                     $constraint->add_column($table->get_column($fdata->{name}));
-#                     $table->add_constraint($constraint);
                 }
     
                 for my $cdata ( @{ $fdata->{constraints} } ) {
@@ -131,11 +128,10 @@ role SQL::Translator::Parser::DDL::MySQL {
             for my $cdata ( @{ $tdata->{constraints} || [] } ) {
                 my $constraint;
                 if (uc $cdata->{type} eq 'PRIMARY_KEY') {
-                    $constraint = PrimaryKey->new({ name => $cdata->{name} || 'primary_key', table => $table });
-                    $constraint->add_column($table->get_column($_)) for @{$cdata->{fields}};
-                $table->get_column($_)->is_primary_key(1) for @{$cdata->{fields}};
+                    $constraint = PrimaryKey->new({ name => $cdata->{name} || '', table => $table });
+                    $table->get_column($_)->is_primary_key(1) for @{$cdata->{fields}};
                 } elsif (uc $cdata->{type} eq 'FOREIGN_KEY') {
-                    $constraint = ForeignKey->new({ name => $cdata->{name} || 'foreign_key',
+                    $constraint = ForeignKey->new({ name => $cdata->{name} || '',
                                                     table => $table,
                                                     reference_table => $cdata->{reference_table},
                                                     reference_columns => $cdata->{reference_fields},
@@ -144,23 +140,10 @@ role SQL::Translator::Parser::DDL::MySQL {
                     $table->get_column($_)->is_foreign_key(1) for @{$cdata->{fields}};
                     $table->get_column($_)->foreign_key_reference($constraint) for @{$cdata->{fields}};
                 } else {
-                    $constraint = Constraint->new({ name => $cdata->{name} || 'constraint', type => uc $cdata->{type}, table => $table });
-                    $constraint->add_column($table->get_column($_)) for @{$cdata->{fields}};
+                    $constraint = Constraint->new({ name => $cdata->{name} || '', type => uc $cdata->{type}, table => $table });
                 }
+                $constraint->add_column($table->get_column($_)) for @{$cdata->{fields}};
                 $table->add_constraint($constraint);
-
-#                my $constraint       =  $table->add_constraint(
-#                    name             => $cdata->{'name'},
-#                    type             => $cdata->{'type'},
-#                    fields           => $cdata->{'fields'},
-#                    reference_table  => $cdata->{'reference_table'},
-#                    reference_fields => $cdata->{'reference_fields'},
-#                    match_type       => $cdata->{'match_type'} || '',
-#                    on_delete        => $cdata->{'on_delete'} 
-#                                     || $cdata->{'on_delete_do'},
-#                    on_update        => $cdata->{'on_update'} 
-#                                     || $cdata->{'on_update_do'},
-#                ) or die $table->error;
             }
     
             # After the constrains and PK/idxs have been created,