From: Arthur Axel 'fREW' Schmidt Date: Thu, 10 Mar 2011 03:49:33 +0000 (-0600) Subject: migrate table to Generator::Role::DDL X-Git-Tag: v0.11011~27^2~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7a16a53e0db93fa50cd41e92afc53d82a90131eb;p=dbsrgits%2FSQL-Translator.git migrate table to Generator::Role::DDL --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLServer.pm b/lib/SQL/Translator/Generator/DDL/SQLServer.pm index 15bab3a..18b399f 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLServer.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLServer.pm @@ -2,6 +2,7 @@ package SQL::Translator::Generator::DDL::SQLServer; use Moo; use SQL::Translator::Generator::Utils; +use SQL::Translator::Schema::Constants; with 'SQL::Translator::Generator::Role::DDL'; @@ -141,5 +142,28 @@ sub enum_constraint { ) } +sub table { + my ($self, $table) = @_; + 'CREATE TABLE ' . $self->quote($table->name) . " (\n". + join( ",\n", + map { " $_" } + # field defs + ( map $self->field($_), $table->get_fields ), + # constraint defs + (map $self->enum_constraint($_->name, { $_->extra }->{list} || []), + grep { 'enum' eq lc $_->data_type } $table->get_fields), + + (map $self->primary_key_constraint($_), + grep { $_->type eq PRIMARY_KEY } $table->get_constraints), + + (map $self->unique_constraint_single($_), + grep { + $_->type eq UNIQUE && + !grep { $_->is_nullable } $_->fields + } $table->get_constraints), + ) . + "\n);", +} + 1; diff --git a/lib/SQL/Translator/Producer/SQLServer.pm b/lib/SQL/Translator/Producer/SQLServer.pm index ded928d..4dbfee0 100644 --- a/lib/SQL/Translator/Producer/SQLServer.pm +++ b/lib/SQL/Translator/Producer/SQLServer.pm @@ -135,26 +135,8 @@ sub produce { $output .= join( "\n\n", @comments, - qq[CREATE TABLE $table_name_ur (\n]. - join( ",\n", - map { " $_" } - # field defs - ( map $future->field($_), $table->get_fields ), - # constraint defs - (map $future->enum_constraint($_->name, { $_->extra }->{list} || []), - grep { 'enum' eq lc $_->data_type } $table->get_fields), - - (map $future->primary_key_constraint($_), - grep { $_->type eq PRIMARY_KEY } $table->get_constraints), - - (map $future->unique_constraint_single($_), - grep { - $_->type eq UNIQUE && - !grep { $_->is_nullable } $_->fields - } $table->get_constraints), - ). - "\n);", # index defs + $future->table($table), (map $future->unique_constraint_multiple($_), grep { $_->type eq UNIQUE &&