From: Arthur Axel 'fREW' Schmidt Date: Fri, 11 Mar 2011 03:58:25 +0000 (-0600) Subject: add unique_constraints_multiple and indices X-Git-Tag: v0.11011~27^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f9e80bf21911a9e31c47cc51de18a00d4840b0c;p=dbsrgits%2FSQL-Translator.git add unique_constraints_multiple and indices --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLServer.pm b/lib/SQL/Translator/Generator/DDL/SQLServer.pm index 649fc7e..c417844 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLServer.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLServer.pm @@ -160,13 +160,25 @@ sub constraints { sub table { my ($self, $table) = @_; - 'CREATE TABLE ' . $self->quote($table->name) . " (\n". - join( ",\n", - map { " $_" } - $self->fields($table), - $self->constraints($table), - ) . - "\n);", + join ( "\n\n", + $self->table_comments($table), + 'CREATE TABLE ' . $self->quote($table->name) . " (\n". + join( ",\n", + map { " $_" } + $self->fields($table), + $self->constraints($table), + ) . + "\n);" + ) +} + +sub unique_constraints_multiple { + my ($self, $table) = @_; + (map $self->unique_constraint_multiple($_), + grep { + $_->type eq UNIQUE && + grep { $_->is_nullable } $_->fields + } $table->get_constraints) } sub drop_table { diff --git a/lib/SQL/Translator/Generator/Role/DDL.pm b/lib/SQL/Translator/Generator/Role/DDL.pm index e9795a9..f7c2964 100644 --- a/lib/SQL/Translator/Generator/Role/DDL.pm +++ b/lib/SQL/Translator/Generator/Role/DDL.pm @@ -83,6 +83,11 @@ sub fields { ( map $self->field($_), $table->get_fields ) } +sub indices { + my ($self, $table) = @_; + (map $self->index($_), $table->get_indices) +} + sub nullable { 'NULL' } sub header_comments { header_comment() . "\n" if $_[0]->add_comments } diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index 1a952a2..010a742 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -24,16 +24,9 @@ sub produce { for my $table ( grep { $_->name } $schema->get_tables ) { $output .= join( "\n\n", - $future->table_comments($table), - # index defs $future->table($table), - (map $future->unique_constraint_multiple($_), - grep { - $_->type eq UNIQUE && - grep { $_->is_nullable } $_->fields - } $table->get_constraints), - - (map $future->index($_), $table->get_indices) + $future->unique_constraints_multiple($table), + $future->indices($table), ); }