From: Justin Hunter Date: Tue, 28 Jun 2011 05:08:33 +0000 (-0400) Subject: add constraints after all tables are added X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=HEAD;p=dbsrgits%2FSQL-Translator-2.0-ish.git add constraints after all tables are added --- diff --git a/lib/SQL/Translator/Parser/DDL/MySQL.pm b/lib/SQL/Translator/Parser/DDL/MySQL.pm index e577f33..2a23fda 100644 --- a/lib/SQL/Translator/Parser/DDL/MySQL.pm +++ b/lib/SQL/Translator/Parser/DDL/MySQL.pm @@ -126,7 +126,26 @@ role SQL::Translator::Parser::DDL::MySQL { } $table->options( \@cleaned_options ); # or die $table->error; } + } + + for my $proc_name ( keys %{ $result->{procedures} } ) { + my $procedure = Procedure->new({ name => $proc_name, + owner => $result->{procedures}->{$proc_name}->{owner}, + sql => $result->{procedures}->{$proc_name}->{sql} + }); + $schema->add_procedure($procedure); + } + for my $view_name ( keys %{ $result->{'views'} } ) { + my $view = View->new({ + name => $view_name, + sql => $result->{'views'}->{$view_name}->{sql}, + }); + $schema->add_view($view); + } + for my $table_name (@tables) { + my $table = $schema->get_table($table_name); + my $tdata = $result->{tables}{ $table_name }; for my $cdata ( @{ $tdata->{constraints} || [] } ) { my $constraint; if (uc $cdata->{type} eq 'PRIMARY_KEY') { @@ -148,22 +167,6 @@ role SQL::Translator::Parser::DDL::MySQL { $table->add_constraint($constraint); } } - - for my $proc_name ( keys %{ $result->{procedures} } ) { - my $procedure = Procedure->new({ name => $proc_name, - owner => $result->{procedures}->{$proc_name}->{owner}, - sql => $result->{procedures}->{$proc_name}->{sql} - }); - $schema->add_procedure($procedure); - } - - for my $view_name ( keys %{ $result->{'views'} } ) { - my $view = View->new({ - name => $view_name, - sql => $result->{'views'}->{$view_name}->{sql}, - }); - $schema->add_view($view); - } return 1; } }