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),
)
}
$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;
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 ()
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;