X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F86sqlt.t;h=079a252fea241492bcb2998e0d8cf1b43cdb07a5;hb=0f7557a2d1f00935aee40823ad1389931a44fed0;hp=7a76f79d19032f74aa23c5cba74960a3442972e2;hpb=c385ecea5ec4297f269bcc2b8db8e08f5772196d;p=dbsrgits%2FDBIx-Class.git diff --git a/t/86sqlt.t b/t/86sqlt.t index 7a76f79..079a252 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 => 77; 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 @@ -43,13 +42,13 @@ my %fk_constraints = ( 'display' => 'twokeys->cd', 'selftable' => 'twokeys', 'foreigntable' => 'cd', 'selfcols' => ['cd'], 'foreigncols' => ['cdid'], - on_delete => '', on_update => '', + on_delete => '', on_update => '', deferrable => 0, }, { 'display' => 'twokeys->artist', 'selftable' => 'twokeys', 'foreigntable' => 'artist', 'selfcols' => ['artist'], 'foreigncols' => ['artistid'], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 0, }, ], @@ -59,14 +58,14 @@ my %fk_constraints = ( 'display' => 'fourkeys_to_twokeys->twokeys', 'selftable' => 'fourkeys_to_twokeys', 'foreigntable' => 'twokeys', 'selfcols' => ['t_artist', 't_cd'], 'foreigncols' => ['artist', 'cd'], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 0, }, { 'display' => 'fourkeys_to_twokeys->fourkeys', 'selftable' => 'fourkeys_to_twokeys', 'foreigntable' => 'fourkeys', 'selfcols' => [qw(f_foo f_bar f_hello f_goodbye)], 'foreigncols' => [qw(foo bar hello goodbye)], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 0, }, ], @@ -76,13 +75,13 @@ my %fk_constraints = ( 'display' => 'cd_to_producer->cd', 'selftable' => 'cd_to_producer', 'foreigntable' => 'cd', 'selfcols' => ['cd'], 'foreigncols' => ['cdid'], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 0, }, { 'display' => 'cd_to_producer->producer', 'selftable' => 'cd_to_producer', 'foreigntable' => 'producer', 'selfcols' => ['producer'], 'foreigncols' => ['producerid'], - on_delete => '', on_update => '', + on_delete => '', on_update => '', deferrable => 0, }, ], @@ -92,13 +91,13 @@ my %fk_constraints = ( 'display' => 'self_ref_alias->self_ref for self_ref', 'selftable' => 'self_ref_alias', 'foreigntable' => 'self_ref', 'selfcols' => ['self_ref'], 'foreigncols' => ['id'], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 0, }, { 'display' => 'self_ref_alias->self_ref for alias', 'selftable' => 'self_ref_alias', 'foreigntable' => 'self_ref', 'selfcols' => ['alias'], 'foreigncols' => ['id'], - on_delete => '', on_update => '', + on_delete => '', on_update => '', deferrable => 0, }, ], @@ -108,7 +107,7 @@ my %fk_constraints = ( 'display' => 'cd->artist', 'selftable' => 'cd', 'foreigntable' => 'artist', 'selfcols' => ['artist'], 'foreigncols' => ['artistid'], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1, }, ], @@ -118,13 +117,13 @@ my %fk_constraints = ( 'display' => 'artist_undirected_map->artist for id1', 'selftable' => 'artist_undirected_map', 'foreigntable' => 'artist', 'selfcols' => ['id1'], 'foreigncols' => ['artistid'], - on_delete => 'CASCADE', on_update => '', + on_delete => 'CASCADE', on_update => '', deferrable => 0, }, { 'display' => 'artist_undirected_map->artist for id2', 'selftable' => 'artist_undirected_map', 'foreigntable' => 'artist', 'selfcols' => ['id2'], 'foreigncols' => ['artistid'], - on_delete => 'CASCADE', on_update => '', + on_delete => 'CASCADE', on_update => '', deferrable => 0, }, ], @@ -134,7 +133,7 @@ my %fk_constraints = ( 'display' => 'track->cd', 'selftable' => 'track', 'foreigntable' => 'cd', 'selfcols' => ['cd'], 'foreigncols' => ['cdid'], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 0, }, ], @@ -144,7 +143,7 @@ my %fk_constraints = ( 'display' => 'treelike->treelike for parent', 'selftable' => 'treelike', 'foreigntable' => 'treelike', 'selfcols' => ['parent'], 'foreigncols' => ['id'], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 0, }, ], @@ -154,7 +153,7 @@ my %fk_constraints = ( 'display' => 'twokeytreelike->twokeytreelike for parent1,parent2', 'selftable' => 'twokeytreelike', 'foreigntable' => 'twokeytreelike', 'selfcols' => ['parent1', 'parent2'], 'foreigncols' => ['id1','id2'], - on_delete => '', on_update => '', + on_delete => '', on_update => '', deferrable => 0, }, ], @@ -164,7 +163,7 @@ my %fk_constraints = ( 'display' => 'tags->cd', 'selftable' => 'tags', 'foreigntable' => 'cd', 'selfcols' => ['cd'], 'foreigncols' => ['cdid'], - on_delete => 'CASCADE', on_update => 'CASCADE', + on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 0, }, ], @@ -174,9 +173,19 @@ my %fk_constraints = ( 'display' => 'bookmark->link', 'selftable' => 'bookmark', 'foreigntable' => 'link', 'selfcols' => ['link'], 'foreigncols' => ['id'], - on_delete => '', on_update => '', + on_delete => '', on_update => '', deferrable => 0, }, ], + # ForceForeign + forceforeign => [ + { + 'display' => 'forceforeign->artist', + 'selftable' => 'forceforeign', 'foreigntable' => 'artist', + 'selfcols' => ['artist'], 'foreigncols' => ['artist_id'], + on_delete => '', on_update => '', deferrable => 0, + }, + ], + ); my %unique_constraints = ( @@ -214,7 +223,7 @@ my %unique_constraints = ( # ], ); -my %indices = ( +my %indexes = ( artist => [ { 'fields' => ['name'] @@ -223,12 +232,17 @@ my %indices = ( ); 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' ); $constraint = get_constraint('UNIQUE', 'cd', ['artist']); ok( !defined($constraint), 'nonexistent UNIQUE constraint not found' ); +$constraint = get_constraint('FOREIGN KEY', 'forceforeign', ['cd'], 'cd', ['cdid']); +ok( !defined($constraint), 'forced nonexistent FOREIGN KEY constraint not found' ); for my $expected_constraints (keys %fk_constraints) { for my $expected_constraint (@{ $fk_constraints{$expected_constraints} }) { @@ -253,8 +267,8 @@ for my $expected_constraints (keys %unique_constraints) { } } -for my $table_index (keys %indices) { - for my $expected_index ( @{ $indices{$table_index} } ) { +for my $table_index (keys %indexes) { + for my $expected_index ( @{ $indexes{$table_index} } ) { ok ( get_index($table_index, $expected_index), "Got a matching index on $table_index table"); } @@ -345,4 +359,6 @@ sub test_fk { "on_delete parameter correct for `$desc'" ); is( $got->on_update, $expected->{on_update}, "on_update parameter correct for `$desc'" ); + is( $got->deferrable, $expected->{deferrable}, + "is_deferrable parameter correct for `$desc'" ); }