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 # CustomSql tests the horrific/deprecated ->name(\$sql) hack
19 # YearXXXXCDs are views
22 { $_ !~ /^ (?: Dummy | CustomSql | Year\d{4}CDs ) $/x }
26 plan tests => ( @sources * 3);
29 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } });
31 foreach my $source (@sources) {
32 my $table = get_table($sqlt_schema, $schema, $source);
34 my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
35 my @indices = $table->get_indices;
36 my $index_count = scalar(@indices);
37 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
38 is($index_count, $fk_count, "correct number of indices for $source with no args");
43 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 1 } } });
45 foreach my $source (@sources) {
46 my $table = get_table($sqlt_schema, $schema, $source);
48 my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
49 my @indices = $table->get_indices;
50 my $index_count = scalar(@indices);
51 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
52 is($index_count, $fk_count, "correct number of indices for $source with add_fk_index => 1");
57 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 0 } } });
59 foreach my $source (@sources) {
60 my $table = get_table($sqlt_schema, $schema, $source);
62 my @indices = $table->get_indices;
63 my $index_count = scalar(@indices);
64 is($index_count, 0, "correct number of indices for $source with add_fk_index => 0");
71 my $schema = $args->{schema};
72 my $additional_sqltargs = $args->{args} || {};
76 ignore_constraint_names => 1,
77 ignore_index_names => 1,
78 %{$additional_sqltargs}
81 my $sqlt = SQL::Translator->new( $sqltargs );
83 $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
84 return $sqlt->translate({ data => $schema }) or die $sqlt->error;
88 my ($sqlt_schema, $schema, $source) = @_;
90 my $table_name = $schema->source($source)->from;
91 $table_name = $$table_name if ref $table_name;
93 return $sqlt_schema->get_table($table_name);