From: Peter Rabbitson Date: Thu, 20 Aug 2009 05:50:49 +0000 (+0000) Subject: Fix a weird-ass sqlt invocation in deployment_statements() X-Git-Tag: v0.08111~67 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0fd7e9a31038c6d19a65ee387657c14b12248623;p=dbsrgits%2FDBIx-Class.git Fix a weird-ass sqlt invocation in deployment_statements() --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index b8f3ebb..e08ff9c 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -2303,18 +2303,18 @@ sub deployment_statements { . $self->_check_sqlt_message . q{'}) if !$self->_check_sqlt_version; - require SQL::Translator::Parser::DBIx::Class; - eval qq{use SQL::Translator::Producer::${type}}; - $self->throw_exception($@) if $@; - # sources needs to be a parser arg, but for simplicty allow at top level # coming in $sqltargs->{parser_args}{sources} = delete $sqltargs->{sources} if exists $sqltargs->{sources}; - my $tr = SQL::Translator->new(%$sqltargs); - SQL::Translator::Parser::DBIx::Class::parse( $tr, $schema ); - return "SQL::Translator::Producer::${type}"->can('produce')->($tr); + my $tr = SQL::Translator->new( + producer => "SQL::Translator::Producer::${type}", + %$sqltargs, + parser => 'SQL::Translator::Parser::DBIx::Class', + data => $schema, + ); + return $tr->translate; } sub deploy { diff --git a/t/86sqlt.t b/t/86sqlt.t index 467fed3..65f2dc8 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -8,9 +8,29 @@ use DBICTest; eval "use SQL::Translator"; plan skip_all => 'SQL::Translator required' if $@; -my $schema = DBICTest->init_schema; +my $schema = DBICTest->init_schema (no_deploy => 1); + +# replace the sqlt calback with a custom version ading an index +$schema->source('Track')->sqlt_deploy_callback(sub { + my ($self, $sqlt_table) = @_; + + is ( + $sqlt_table->schema->translator->producer_type, + join ('::', 'SQL::Translator::Producer', $schema->storage->sqlt_type), + 'Production type passed to translator object', + ); + + if ($schema->storage->sqlt_type eq 'SQLite' ) { + $sqlt_table->add_index( name => 'track_title', fields => ['title'] ) + or die $sqlt_table->error; + } + + $self->default_sqlt_deploy_hook($sqlt_table); +}); + +$schema->deploy; # do not remove, this fires the is() test in the callback above + -plan tests => 133; my $translator = SQL::Translator->new( parser_args => { @@ -26,16 +46,6 @@ my $translator = SQL::Translator->new( my $relinfo = $schema->source('Artist')->relationship_info ('cds'); local $relinfo->{attrs}{on_delete} = 'restrict'; - $schema->source('Track')->sqlt_deploy_callback(sub { - my ($self, $sqlt_table) = @_; - - if ($schema->storage->sqlt_type eq 'SQLite' ) { - $sqlt_table->add_index( name => 'track_title', fields => ['title'] ) - or die $sqlt_table->error; - } - - $self->default_sqlt_deploy_hook($sqlt_table); - }); $translator->parser('SQL::Translator::Parser::DBIx::Class'); $translator->producer('SQLite'); @@ -45,6 +55,7 @@ my $translator = SQL::Translator->new( ok($output, "SQLT produced someoutput") or diag($translator->error); + like ( $warn, qr/SQLT attribute .+? was supplied for relationship .+? which does not appear to be a foreign constraint/, @@ -443,3 +454,5 @@ sub test_unique { is( $got->name, $expected->{name}, "name parameter correct for `$desc'" ); } + +done_testing; diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 86e345e..1938e87 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -1,6 +1,6 @@ -- -- Created by SQL::Translator::Producer::SQLite --- Created on Wed Aug 12 16:10:43 2009 +-- Created on Thu Aug 20 07:47:13 2009 -- @@ -16,6 +16,8 @@ CREATE TABLE artist ( charfield char(10) ); +CREATE INDEX artist_name_hookidx ON artist (name); + -- -- Table: bindtype_test --