From: Justin Hunter Date: Wed, 22 Sep 2010 15:43:09 +0000 (-0700) Subject: fix up is_nullable and is_unique being wrong at times X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f897a63d37d3096c6535a2417aefe599057400f;p=dbsrgits%2FSQL-Translator-2.0-ish.git fix up is_nullable and is_unique being wrong at times --- diff --git a/lib/SQL/Translator/Parser/DDL/SQLite.pm b/lib/SQL/Translator/Parser/DDL/SQLite.pm index 5fc6d34..c5406c5 100644 --- a/lib/SQL/Translator/Parser/DDL/SQLite.pm +++ b/lib/SQL/Translator/Parser/DDL/SQLite.pm @@ -54,7 +54,7 @@ role SQL::Translator::Parser::DDL::SQLite { size => $fdata->{size}, default_value => $fdata->{default}, is_auto_increment => $fdata->{is_auto_inc}, - is_nullable => $fdata->{is_nullable}, + is_nullable => $fdata->{is_primary_key} ? 0 : $fdata->{is_nullable}, comments => $fdata->{comments}, table => $table, }); @@ -84,8 +84,12 @@ role SQL::Translator::Parser::DDL::SQLite { my $constraint; if (uc $cdata->{type} eq 'PRIMARY_KEY') { $constraint = PrimaryKey->new({ name => $cdata->{name} || 'primary_key', table => $table }); - $constraint->add_column($table->get_column($_)) for @{$cdata->{fields}}; - $table->get_column($_)->is_primary_key(1) for @{$cdata->{fields}}; + + for my $field (@{$cdata->{fields}}) { + $table->get_column($field)->is_primary_key(1); + $table->get_column($field)->is_nullable(0); + $constraint->add_column($table->get_column($field)); + } } elsif (uc $cdata->{type} eq 'FOREIGN_KEY') { $constraint = ForeignKey->new({ name => $cdata->{name} || 'foreign_key', table => $table, @@ -93,12 +97,19 @@ role SQL::Translator::Parser::DDL::SQLite { reference_columns => ref $cdata->{reference_fields} ? $cdata->{reference_fields} : [ $cdata->{reference_fields} ], on_delete => $cdata->{on_delete} || $cdata->{on_delete_do}, on_update => $cdata->{on_update} || $cdata->{on_update_do} }); - $table->get_column($_)->is_foreign_key(1) for @{$cdata->{fields}}; - $table->get_column($_)->foreign_key_reference($constraint) for @{$cdata->{fields}}; + for my $field (@{$cdata->{fields}}) { + $table->get_column($field)->is_foreign_key(1); + $table->get_column($field)->foreign_key_reference($constraint); + $constraint->add_column($table->get_column($field)); + } } else { $constraint = Constraint->new({ name => $cdata->{name} || 'constraint', type => uc $cdata->{type}, table => $table }); + if (uc $cdata->{type} eq 'UNIQUE') { + $table->get_column($_)->is_unique(1) for @{$cdata->{fields}}; + } $constraint->add_column($table->get_column($_)) for @{$cdata->{fields}}; } + $table->add_constraint($constraint); } }