From: Arthur Axel 'fREW' Schmidt Date: Fri, 11 Mar 2011 04:05:20 +0000 (-0600) Subject: migrate almost all code to Generator::Role::DDL X-Git-Tag: v0.11011~27^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9a6c1bf9089e2b6dcd68fd034c55b41b074c14b0;p=dbsrgits%2FSQL-Translator.git migrate almost all code to Generator::Role::DDL --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLServer.pm b/lib/SQL/Translator/Generator/DDL/SQLServer.pm index c417844..4fc4466 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLServer.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLServer.pm @@ -160,15 +160,17 @@ sub constraints { sub table { my ($self, $table) = @_; + join ( "\n", $self->table_comments($table), '' ) . join ( "\n\n", - $self->table_comments($table), 'CREATE TABLE ' . $self->quote($table->name) . " (\n". join( ",\n", map { " $_" } $self->fields($table), $self->constraints($table), ) . - "\n);" + "\n);", + $self->unique_constraints_multiple($table), + $self->indices($table), ) } @@ -230,5 +232,14 @@ sub foreign_key_constraints { $schema->get_tables ) } +sub schema { + my ($self, $schema) = @_; + + $self->header_comments . + $self->drop_tables($schema) . + join("\n\n", map $self->table($_), grep { $_->name } $schema->get_tables) . + "\n" . join "\n", $self->foreign_key_constraints($schema) +} + 1; diff --git a/lib/SQL/Translator/Generator/Role/DDL.pm b/lib/SQL/Translator/Generator/Role/DDL.pm index f7c2964..5533a01 100644 --- a/lib/SQL/Translator/Generator/Role/DDL.pm +++ b/lib/SQL/Translator/Generator/Role/DDL.pm @@ -50,11 +50,11 @@ sub table_comments { my ($self, $table) = @_; if ($self->add_comments) { return ( - "\n", - "--\n", - "-- Table: " . $self->quote($table->name) . "\n", - "--\n", - map "-- $_\n", $table->comments + "", + "--", + "-- Table: " . $self->quote($table->name) . "", + "--", + map "-- $_", $table->comments ) } else { return () diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index 010a742..cbab3c0 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -11,29 +11,11 @@ use SQL::Translator::Utils qw(debug header_comment); use SQL::Translator::Generator::DDL::SQLServer; sub produce { - my $translator = shift; - my $future = SQL::Translator::Generator::DDL::SQLServer->new( - add_comments => !$translator->no_comments, - add_drop_tables => $translator->add_drop_table, - ); - - my $schema = $translator->schema; - - my $output = $future->header_comments - . $future->drop_tables($schema); - - for my $table ( grep { $_->name } $schema->get_tables ) { - $output .= join( "\n\n", - $future->table($table), - $future->unique_constraints_multiple($table), - $future->indices($table), - ); - } - - my @foreign_constraints = $future->foreign_key_constraints($schema); - $output .= join ("\n", '', @foreign_constraints) if @foreign_constraints; - - return $output; + my $translator = shift; + SQL::Translator::Generator::DDL::SQLServer->new( + add_comments => !$translator->no_comments, + add_drop_tables => $translator->add_drop_table, + )->schema($translator->schema) } 1;