show Oracle datetime_setup alter session statements in debug output
[dbsrgits/DBIx-Class.git] / t / 99dbic_sqlt_parser.t
CommitLineData
0e2c6809 1#!/usr/bin/perl
2use strict;
3use warnings;
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
1dac6833 8
0e2c6809 9BEGIN {
1b840063 10 eval "use SQL::Translator 0.09003;";
1dac6833 11 if ($@) {
1b840063 12 plan skip_all => 'needs SQL::Translator 0.09003 for testing';
1dac6833 13 }
0e2c6809 14}
15
16my $schema = DBICTest->init_schema();
0fc7cd47 17# Dummy was yanked out by the sqlt hook test
18# YearXXXXCDs are views
19my @sources = grep { $_ ne 'Dummy' && $_ !~ /^Year\d{4}CDs$/ }
20 $schema->sources;
21
181c0934 22plan tests => ( @sources * 3);
0e2c6809 23
24{
25 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } });
26
181c0934 27 foreach my $source (@sources) {
0e2c6809 28 my $table = $sqlt_schema->get_table($schema->source($source)->from);
29
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);
2581038c 33 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
0e2c6809 34 is($index_count, $fk_count, "correct number of indices for $source with no args");
35 }
36}
37
38{
39 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 1 } } });
40
181c0934 41 foreach my $source (@sources) {
0e2c6809 42 my $table = $sqlt_schema->get_table($schema->source($source)->from);
43
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);
2581038c 47 $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
0e2c6809 48 is($index_count, $fk_count, "correct number of indices for $source with add_fk_index => 1");
49 }
50}
51
52{
53 my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 0 } } });
54
181c0934 55 foreach my $source (@sources) {
0e2c6809 56 my $table = $sqlt_schema->get_table($schema->source($source)->from);
57
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");
61 }
62}
63
64sub create_schema {
65 my $args = shift;
66
67 my $schema = $args->{schema};
68 my $additional_sqltargs = $args->{args} || {};
69
70 my $sqltargs = {
71 add_drop_table => 1,
72 ignore_constraint_names => 1,
73 ignore_index_names => 1,
74 %{$additional_sqltargs}
75 };
76
77 my $sqlt = SQL::Translator->new( $sqltargs );
78
79 $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
80 return $sqlt->translate({ data => $schema }) or die $sqlt->error;
81}