10 eval "use SQL::Translator 0.09003;";
12 plan skip_all => 'needs SQL::Translator 0.09003 for testing';
16 my $schema = DBICTest->init_schema();
17 # Dummy was yanked out by the sqlt hook test
18 # YearXXXXCDs are views
19 my @sources = grep { $_ ne 'Dummy' && $_ !~ /^Year\d{4}CDs$/ }
22 plan tests => ( @sources * 3);
25 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } });
27 foreach my $source (@sources) {
28 my $table = $sqlt_schema->get_table($schema->source($source)->from);
30 my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
31 my @indices = $table->get_indices;
32 my $index_count = scalar(@indices);
33 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
34 is($index_count, $fk_count, "correct number of indices for $source with no args");
39 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 1 } } });
41 foreach my $source (@sources) {
42 my $table = $sqlt_schema->get_table($schema->source($source)->from);
44 my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
45 my @indices = $table->get_indices;
46 my $index_count = scalar(@indices);
47 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
48 is($index_count, $fk_count, "correct number of indices for $source with add_fk_index => 1");
53 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 0 } } });
55 foreach my $source (@sources) {
56 my $table = $sqlt_schema->get_table($schema->source($source)->from);
58 my @indices = $table->get_indices;
59 my $index_count = scalar(@indices);
60 is($index_count, 0, "correct number of indices for $source with add_fk_index => 0");
67 my $schema = $args->{schema};
68 my $additional_sqltargs = $args->{args} || {};
72 ignore_constraint_names => 1,
73 ignore_index_names => 1,
74 %{$additional_sqltargs}
77 my $sqlt = SQL::Translator->new( $sqltargs );
79 $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
80 return $sqlt->translate({ data => $schema }) or die $sqlt->error;