From: Ash Berlin Date: Fri, 12 Oct 2007 18:20:43 +0000 (+0000) Subject: Test sqlt_deploy_hook on the Schema level X-Git-Tag: v0.08010~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6c79cb31fbee489d8daa06e9890c828b1381f3b;p=dbsrgits%2FDBIx-Class.git Test sqlt_deploy_hook on the Schema level --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index a53a7a5..58d2be9 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -67,8 +67,6 @@ sub parse { foreach my $moniker (@monikers) { - #eval "use $tableclass"; - #print("Can't load $tableclass"), next if($@); my $source = $dbixschema->source($moniker); next if $seen_tables{$source->name}++; @@ -80,7 +78,7 @@ sub parse { my $colcount = 0; foreach my $col ($source->columns) { - # assuming column_info in dbix is the same as DBI (?) + # assuming column_info in dbic is the same as DBI (?) # data_type is a number, column_type is text? my %colinfo = ( name => $col, @@ -175,6 +173,11 @@ sub parse { $source->result_class->sqlt_deploy_hook($table); } } + + if ($dbixschema->can('sqlt_deploy_hook')) { + $dbixschema->sqlt_deploy_hook($schema); + } + return 1; } diff --git a/t/86sqlt.t b/t/86sqlt.t index c70be74..0d3a759 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -10,7 +10,7 @@ plan skip_all => 'SQL::Translator required' if $@; my $schema = DBICTest->init_schema; -plan tests => 55; +plan tests => 56; my $translator = SQL::Translator->new( parser_args => { @@ -28,7 +28,6 @@ my $output = $translator->translate(); ok($output, "SQLT produced someoutput") or diag($translator->error); - # Note that the constraints listed here are the only ones that are tested -- if # more exist in the Schema than are listed here and all listed constraints are # correct, the test will still pass. If you add a class with UNIQUE or FOREIGN @@ -224,6 +223,10 @@ my %indexes = ( my $tschema = $translator->schema(); +# Test that the $schema->sqlt_deploy_hook was called okay and that it removed +# the 'link' table +ok( !defined($tschema->get_table('link')), "Link table was removed by hook"); + # Test that nonexistent constraints are not found my $constraint = get_constraint('FOREIGN KEY', 'cd', ['title'], 'cd', ['year']); ok( !defined($constraint), 'nonexistent FOREIGN KEY constraint not found' ); diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index b2e4099..979cf84 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -39,4 +39,10 @@ __PACKAGE__->load_classes(qw/ qw/Owners BooksInLibrary/ ); +sub sqlt_deploy_hook { + my ($self, $sqlt_schema) = @_; + + $sqlt_schema->drop_table('link'); +} + 1; diff --git a/t/lib/DBICTest/Schema/Artist.pm b/t/lib/DBICTest/Schema/Artist.pm index 424fbe9..2221029 100644 --- a/t/lib/DBICTest/Schema/Artist.pm +++ b/t/lib/DBICTest/Schema/Artist.pm @@ -44,8 +44,11 @@ __PACKAGE__->has_many( sub sqlt_deploy_hook { my ($self, $sqlt_table) = @_; - $sqlt_table->add_index( name => 'artist_name', fields => ['name'] ) - or die $sqlt_table->error; + + if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) { + $sqlt_table->add_index( name => 'artist_name', fields => ['name'] ) + or die $sqlt_table->error; + } } 1;