From: Arthur Axel 'fREW' Schmidt Date: Fri, 11 Mar 2011 03:53:09 +0000 (-0600) Subject: add foreign_key_constraints X-Git-Tag: v0.11011~27^2~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c709166063bd128e162fbecb08c96fec46bc4035;p=dbsrgits%2FSQL-Translator.git add foreign_key_constraints --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLServer.pm b/lib/SQL/Translator/Generator/DDL/SQLServer.pm index 5852998..649fc7e 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLServer.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLServer.pm @@ -210,5 +210,13 @@ sub drop_tables { return ''; } +sub foreign_key_constraints { + my ($self, $schema) = @_; + ( map $self->foreign_key_constraint($_), + grep { $_->type eq FOREIGN_KEY } + map $_->get_constraints, + $schema->get_tables ) +} + 1; diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index 1812418..1a952a2 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -17,19 +17,12 @@ sub produce { add_drop_tables => $translator->add_drop_table, ); - my $no_comments = $translator->no_comments; - my $add_drop_table = $translator->add_drop_table; my $schema = $translator->schema; my $output = $future->header_comments . $future->drop_tables($schema); - my @foreign_constraints = (); - for my $table ( grep { $_->name } $schema->get_tables ) { - push @foreign_constraints, map $future->foreign_key_constraint($_), - grep { $_->type eq FOREIGN_KEY } $table->get_constraints; - $output .= join( "\n\n", $future->table_comments($table), # index defs @@ -44,12 +37,9 @@ sub produce { ); } -# Add FK constraints + my @foreign_constraints = $future->foreign_key_constraints($schema); $output .= join ("\n", '', @foreign_constraints) if @foreign_constraints; -# create view/procedure are NOT prepended to the input $sql, needs -# to be filled in with the proper syntax - return $output; }