From: Arthur Axel 'fREW' Schmidt Date: Fri, 11 Mar 2011 02:53:53 +0000 (-0600) Subject: add table_comments X-Git-Tag: v0.11011~27^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f511a4155f5cd8ce5eb7666d1048b26446652fae;p=dbsrgits%2FSQL-Translator.git add table_comments --- diff --git a/lib/SQL/Translator/Generator/Role/DDL.pm b/lib/SQL/Translator/Generator/Role/DDL.pm index 8339a20..e9795a9 100644 --- a/lib/SQL/Translator/Generator/Role/DDL.pm +++ b/lib/SQL/Translator/Generator/Role/DDL.pm @@ -46,6 +46,21 @@ sub field_comments { ( $_[1]->comments ? ('-- ' . $_[1]->comments . "\n ") : () ) } +sub table_comments { + my ($self, $table) = @_; + if ($self->add_comments) { + return ( + "\n", + "--\n", + "-- Table: " . $self->quote($table->name) . "\n", + "--\n", + map "-- $_\n", $table->comments + ) + } else { + return () + } +} + sub field_nullable { ($_[1]->is_nullable ? $_[0]->nullable : 'NOT NULL' ) } sub field_default { diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index 03a8e97..1812418 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -21,26 +21,17 @@ sub produce { my $add_drop_table = $translator->add_drop_table; my $schema = $translator->schema; - my $output = $future->header_comments; - $output .= $future->drop_tables($schema); + my $output = $future->header_comments + . $future->drop_tables($schema); my @foreign_constraints = (); for my $table ( grep { $_->name } $schema->get_tables ) { - my $table_name_ur = $future->quote($table->name); - - my ( @comments ); - - push @comments, "\n\n--\n-- Table: $table_name_ur\n--" - unless $no_comments; - - push @comments, map { "-- $_" } $table->comments; - push @foreign_constraints, map $future->foreign_key_constraint($_), grep { $_->type eq FOREIGN_KEY } $table->get_constraints; $output .= join( "\n\n", - @comments, + $future->table_comments($table), # index defs $future->table($table), (map $future->unique_constraint_multiple($_),