9 require DBIx::Class::Storage::DBI;
11 'Test needs SQL::Translator ' . DBIx::Class::Storage::DBI->_sqlt_minimum_version
12 if not DBIx::Class::Storage::DBI->_sqlt_version_ok;
15 my $schema = DBICTest->init_schema();
16 # Dummy was yanked out by the sqlt hook test
17 # CustomSql tests the horrific/deprecated ->name(\$sql) hack
18 # YearXXXXCDs are views
21 { $_ !~ /^ (?: Dummy | CustomSql | Year\d{4}CDs ) $/x }
26 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } });
28 foreach my $source (@sources) {
29 my $table = get_table($sqlt_schema, $schema, $source);
31 my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
32 my @indices = $table->get_indices;
33 my $index_count = scalar(@indices);
34 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
35 is($index_count, $fk_count, "correct number of indices for $source with no args");
40 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 1 } } });
42 foreach my $source (@sources) {
43 my $table = get_table($sqlt_schema, $schema, $source);
45 my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
46 my @indices = $table->get_indices;
47 my $index_count = scalar(@indices);
48 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
49 is($index_count, $fk_count, "correct number of indices for $source with add_fk_index => 1");
54 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 0 } } });
56 foreach my $source (@sources) {
57 my $table = get_table($sqlt_schema, $schema, $source);
59 my @indices = $table->get_indices;
60 my $index_count = scalar(@indices);
61 is($index_count, 0, "correct number of indices for $source with add_fk_index => 0");
70 my $schema = $args->{schema};
71 my $additional_sqltargs = $args->{args} || {};
75 ignore_constraint_names => 1,
76 ignore_index_names => 1,
77 %{$additional_sqltargs}
80 my $sqlt = SQL::Translator->new( $sqltargs );
82 $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
83 return $sqlt->translate({ data => $schema }) or die $sqlt->error;
87 my ($sqlt_schema, $schema, $source) = @_;
89 my $table_name = $schema->source($source)->from;
90 $table_name = $$table_name if ref $table_name;
92 return $sqlt_schema->get_table($table_name);