1package TestSchema;
2
3use strict;
4use warnings;
5
6use File::Spec;
7
8our $VERSION = 0.001;
9use parent 'DBIx::Class::Schema';
10
11__PACKAGE__->load_namespaces(
12   default_resultset_class => 'ResultSet',
13);
14
15__PACKAGE__->load_components(qw(
16   Helper::Schema::LintContents
17   Helper::Schema::QuoteNames
18   Helper::Schema::DidYouMean
19));
20
21sub upgrade_directory { './t/lib' }
22
23sub ddl_filename {
24   my $self = shift;
25
26   $_[2] = $self->upgrade_directory;
27
28   $self->next::method(@_)
29}
30
31sub deploy_or_connect {
32   my $self = shift;
33
34   my $schema = $self->connect(@_);
35   $schema->deploy();
36   return $schema;
37}
38
39sub connection {
40   my $self = shift;
41
42   if (@_) {
43      return $self->next::method(@_);
44   } else {
45      return $self->next::method('dbi:SQLite::memory:');
46   }
47}
48
49sub generate_ddl {
50   my $self = shift;
51   my $schema = $self->connect;
52   $schema->create_ddl_dir(
53      $_,
54      $schema->schema_version,
55      undef,
56      undef, {
57          ($_ ne 'SQLite'
58            ? (
59                add_drop_table => 1,
60                filters => [
61                  sub {
62                    #remove circular dependency. Not used for
63                    #non-sqlite tests
64                    my $foo = shift->get_table('Foo');
65                    my @constraints = map { $_->name } $foo->get_constraints;
66                    $foo->drop_constraint($_) for grep { /bar/ } @constraints;
67                  }
68                ]
69              )
70            : ( add_drop_table => 0 )
71         )
72      },
73   ) for qw(SQLite MySQL PostgreSQL SQLServer Oracle);
74}
75
76sub prepopulate {
77   my $self = shift;
78   $self->resultset($_)->delete for qw{Bar Foo Gnarly_Station Bloaty Gnarly Station HasAccessor};
79
80   $self->populate( Gnarly => [
81      [qw{id name}],
82      [1,'frew'],
83      [2,'frioux'],
84      [3,'frooh'],
85   ]);
86
87   $self->populate( Station => [
88      [qw{id name}],
89      [1,'frew'],
90      [2,'frioux'],
91      [3,'frooh'],
92   ]);
93
94   $self->populate( Gnarly_Station => [
95      [qw{gnarly_id station_id}],
96      [1,1],
97      [1,3],
98      [2,1],
99      [3,1],
100   ]);
101
102   $self->populate(Bloaty => [
103      [qw{id name}],
104      [1,1],
105      [2,2],
106      [3,3],
107      [4,4],
108      [5,5],
109   ]);
110
111   $self->populate(Foo => [
112      [qw{id bar_id}],
113      [1,1],
114      [2,2],
115      [3,3],
116      [4,4],
117      [5,5],
118   ]);
119
120   $self->populate(Bar => [
121      [qw{id foo_id}],
122      [1,1],
123      [2,2],
124      [3,3],
125      [4,4],
126      [5,5],
127   ]);
128
129   $self->populate( HasAccessor => [
130      [qw{id usable_column unusable_column}],
131      [1,'aa','bb'],
132      [2,'cc','dd'],
133      [3,'ee','ff'],
134   ]);
135
136   $self->populate(SerializeAll => [
137      [qw{id text_column}],
138      [1,'frew'],
139      [2,'frioux'],
140      [3,'frooh'],
141   ]);
142}
143
144'kitten eater';
145