From: Justin Hunter Date: Sun, 12 Jul 2009 07:24:13 +0000 (-0700) Subject: add drop_table and no_comments attributes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=672dfd6b467f7f4258a1f8c0238b122de9db19cc;p=dbsrgits%2FSQL-Translator-2.0-ish.git add drop_table and no_comments attributes --- diff --git a/lib/SQL/Translator/Producer.pm b/lib/SQL/Translator/Producer.pm index a19eab3..4cc3084 100644 --- a/lib/SQL/Translator/Producer.pm +++ b/lib/SQL/Translator/Producer.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer; use namespace::autoclean; use Moose; -use MooseX::Types::Moose qw(Str); +use MooseX::Types::Moose qw(Bool Str); use SQL::Translator::Types qw(Schema); has 'schema' => ( @@ -10,6 +10,20 @@ has 'schema' => ( required => 1 ); +has 'no_comments' => ( + isa => Bool, + is => 'rw', + lazy => 1, + default => 0 +); + +has 'drop_table' => ( + isa => Bool, + is => 'rw', + lazy => 1, + default => 1 +); + sub produce { my $self = shift; my $schema = $self->schema; diff --git a/lib/SQL/Translator/Producer/SQLite.pm b/lib/SQL/Translator/Producer/SQLite.pm index c019cc2..7aa9bb8 100644 --- a/lib/SQL/Translator/Producer/SQLite.pm +++ b/lib/SQL/Translator/Producer/SQLite.pm @@ -16,14 +16,13 @@ sub _create_table { my $self = shift; my $table = shift; - my $no_comments = 0; - my $add_drop_table = 1; + my $no_comments = $self->no_comments; my $sqlite_version = 0; my $create_table; my (@create, @column_defs, @index_defs, @constraint_defs); - $create_table .= 'DROP TABLE ' . $table->name . ";\n" if $add_drop_table; + $create_table .= 'DROP TABLE ' . $table->name . ";\n" if $self->drop_table; $create_table .= 'CREATE TABLE ' . $table->name . " (\n"; push @column_defs, $self->_create_column($_) for values %{$table->columns};