add unique_constraints_multiple and indices
Arthur Axel 'fREW' Schmidt [Fri, 11 Mar 2011 03:58:25 +0000 (21:58 -0600)]
lib/SQL/Translator/Generator/DDL/SQLServer.pm
lib/SQL/Translator/Generator/Role/DDL.pm
lib/SQL/Translator/Producer/SQLServer.pm

index 649fc7e..c417844 100644 (file)
@@ -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 {
index e9795a9..f7c2964 100644 (file)
@@ -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 }
index 1a952a2..010a742 100644 (file)
@@ -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),
         );
     }