10 eval "use DBD::mysql; use SQL::Translator 0.09003;";
12 plan skip_all => 'needs DBD::mysql and SQL::Translator 0.09003 for testing';
16 my $schema = DBICTest->init_schema();
17 my @sources = grep { $_ ne 'Dummy' } ($schema->sources); # Dummy was yanked out by the sqlt hook test
18 plan tests => ( @sources * 3);
21 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } });
23 foreach my $source (@sources) {
24 my $table = $sqlt_schema->get_table($schema->source($source)->from);
26 my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
27 my @indices = $table->get_indices;
28 my $index_count = scalar(@indices);
29 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
30 is($index_count, $fk_count, "correct number of indices for $source with no args");
35 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 1 } } });
37 foreach my $source (@sources) {
38 my $table = $sqlt_schema->get_table($schema->source($source)->from);
40 my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
41 my @indices = $table->get_indices;
42 my $index_count = scalar(@indices);
43 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
44 is($index_count, $fk_count, "correct number of indices for $source with add_fk_index => 1");
49 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 0 } } });
51 foreach my $source (@sources) {
52 my $table = $sqlt_schema->get_table($schema->source($source)->from);
54 my @indices = $table->get_indices;
55 my $index_count = scalar(@indices);
56 is($index_count, 0, "correct number of indices for $source with add_fk_index => 0");
63 my $schema = $args->{schema};
64 my $additional_sqltargs = $args->{args} || {};
68 ignore_constraint_names => 1,
69 ignore_index_names => 1,
70 %{$additional_sqltargs}
73 my $sqlt = SQL::Translator->new( $sqltargs );
75 $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
76 return $sqlt->translate({ data => $schema }) or die $sqlt->error;