Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 537 lines (455 sloc) 17.464 kb
7035051 Delete basicrels tests. Modify run tests to use new syntax. Remove h…
Aran Deltac authored
1 use strict;
2 use warnings;
3
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
4 use Test::More;
052a832 @ribasushi Make $SIG{__WARN__} overrides more Carp::Always friendly
ribasushi authored
5 use Test::Warn;
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
6 use lib qw(t/lib);
7 use DBICTest;
8
fed15b9 @ribasushi Fix incorrect default sqlt_deploy_hook signature
ribasushi authored
9 use Scalar::Util 'blessed';
10
7f6f5b6 @ribasushi Centralize handling of minimum sqlt version to DBIx::Class
ribasushi authored
11 BEGIN {
2527233 @ribasushi Move sqlt dephandling to Optional::Deps
ribasushi authored
12 require DBIx::Class;
7f6f5b6 @ribasushi Centralize handling of minimum sqlt version to DBIx::Class
ribasushi authored
13 plan skip_all =>
2527233 @ribasushi Move sqlt dephandling to Optional::Deps
ribasushi authored
14 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy')
15 unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy')
7f6f5b6 @ribasushi Centralize handling of minimum sqlt version to DBIx::Class
ribasushi authored
16 }
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
17
c66a805 @rafl Make sure overriding deployment_statements is possible from within sc…
rafl authored
18 my $custom_deployment_statements_called = 0;
19
20 sub DBICTest::Schema::deployment_statements {
21 $custom_deployment_statements_called = 1;
22 my $self = shift;
23 return $self->next::method(@_);
24 }
25
30ae562 @ribasushi Fix deployment_statements context sensitivity regression
ribasushi authored
26
27 # Check deployment statements ctx sensitivity
28 {
6ddb4ac @ribasushi Pass tests with DBICTEST_SQLITE_USE_FILE set
ribasushi authored
29 my $schema = DBICTest->init_schema (no_deploy => 1);
f9b5239 @ribasushi Propagate quote_names setting to SQLite SQLT producer
ribasushi authored
30 my $not_first_table_creation_re = qr/CREATE TABLE "fourkeys_to_twokeys"/;
30ae562 @ribasushi Fix deployment_statements context sensitivity regression
ribasushi authored
31
32 my $statements = $schema->deployment_statements;
33 like (
34 $statements,
35 $not_first_table_creation_re,
36 'All create statements returned in 1 string in scalar ctx'
37 );
38
39 my @statements = $schema->deployment_statements;
40 cmp_ok (scalar @statements, '>', 1, 'Multiple statement lines in array ctx');
41
42 my $i = 0;
43 while ($i <= $#statements) {
44 last if $statements[$i] =~ $not_first_table_creation_re;
45 $i++;
46 }
47
48 ok (
49 ($i > 0) && ($i <= $#statements),
50 "Creation statement was found somewherere within array ($i)"
51 );
52 }
53
fed15b9 @ribasushi Fix incorrect default sqlt_deploy_hook signature
ribasushi authored
54 {
55 # use our own throw-away schema, since we'll be deploying twice
56 my $schema = DBICTest->init_schema (no_deploy => 1);
57
58 my $deploy_hook_called = 0;
59 $custom_deployment_statements_called = 0;
60
61 # add a temporary sqlt_deploy_hook to a source
a267ea8 @melo Added tests for chained sqlt_deploy_hook()'s
melo authored
62 local $DBICTest::Schema::Track::hook_cb = sub {
7f3fd26 @melo Revert "Fix incorrect default sqlt_deploy_hook signature" (fed15b916)
melo authored
63 my ($class, $sqlt_table) = @_;
fed15b9 @ribasushi Fix incorrect default sqlt_deploy_hook signature
ribasushi authored
64
65 $deploy_hook_called = 1;
66
7f3fd26 @melo Revert "Fix incorrect default sqlt_deploy_hook signature" (fed15b916)
melo authored
67 is ($class, 'DBICTest::Track', 'Result class passed to plain hook');
30ae562 @ribasushi Fix deployment_statements context sensitivity regression
ribasushi authored
68
fed15b9 @ribasushi Fix incorrect default sqlt_deploy_hook signature
ribasushi authored
69 is (
70 $sqlt_table->schema->translator->producer_type,
71 join ('::', 'SQL::Translator::Producer', $schema->storage->sqlt_type),
72 'Production type passed to translator object',
73 );
74 };
75
a267ea8 @melo Added tests for chained sqlt_deploy_hook()'s
melo authored
76 my $component_deploy_hook_called = 0;
77 local $DBICTest::DeployComponent::hook_cb = sub {
78 $component_deploy_hook_called = 1;
79 };
80
fed15b9 @ribasushi Fix incorrect default sqlt_deploy_hook signature
ribasushi authored
81 $schema->deploy; # do not remove, this fires the is() test in the callback above
82 ok($deploy_hook_called, 'deploy hook got called');
83 ok($custom_deployment_statements_called, '->deploy used the schemas deploy_statements method');
a267ea8 @melo Added tests for chained sqlt_deploy_hook()'s
melo authored
84 ok($component_deploy_hook_called, 'component deploy hook got called');
fed15b9 @ribasushi Fix incorrect default sqlt_deploy_hook signature
ribasushi authored
85 }
30ae562 @ribasushi Fix deployment_statements context sensitivity regression
ribasushi authored
86
6ddb4ac @ribasushi Pass tests with DBICTEST_SQLITE_USE_FILE set
ribasushi authored
87 my $schema = DBICTest->init_schema (no_deploy => 1);
88
427c408 @rafl Make sure we actually run all tests, given we're using done_testing.
rafl authored
89 {
90 my $deploy_hook_called = 0;
fed15b9 @ribasushi Fix incorrect default sqlt_deploy_hook signature
ribasushi authored
91 $custom_deployment_statements_called = 0;
65d3512 @ribasushi Test suite wide leaktesting
ribasushi authored
92 my $sqlt_type = $schema->storage->sqlt_type;
0fd7e9a @ribasushi Fix a weird-ass sqlt invocation in deployment_statements()
ribasushi authored
93
427c408 @rafl Make sure we actually run all tests, given we're using done_testing.
rafl authored
94 # replace the sqlt calback with a custom version ading an index
95 $schema->source('Track')->sqlt_deploy_callback(sub {
96 my ($self, $sqlt_table) = @_;
0fd7e9a @ribasushi Fix a weird-ass sqlt invocation in deployment_statements()
ribasushi authored
97
427c408 @rafl Make sure we actually run all tests, given we're using done_testing.
rafl authored
98 $deploy_hook_called = 1;
0fd7e9a @ribasushi Fix a weird-ass sqlt invocation in deployment_statements()
ribasushi authored
99
427c408 @rafl Make sure we actually run all tests, given we're using done_testing.
rafl authored
100 is (
101 $sqlt_table->schema->translator->producer_type,
65d3512 @ribasushi Test suite wide leaktesting
ribasushi authored
102 join ('::', 'SQL::Translator::Producer', $sqlt_type),
427c408 @rafl Make sure we actually run all tests, given we're using done_testing.
rafl authored
103 'Production type passed to translator object',
104 );
0fd7e9a @ribasushi Fix a weird-ass sqlt invocation in deployment_statements()
ribasushi authored
105
65d3512 @ribasushi Test suite wide leaktesting
ribasushi authored
106 if ($sqlt_type eq 'SQLite' ) {
427c408 @rafl Make sure we actually run all tests, given we're using done_testing.
rafl authored
107 $sqlt_table->add_index( name => 'track_title', fields => ['title'] )
108 or die $sqlt_table->error;
109 }
110
111 $self->default_sqlt_deploy_hook($sqlt_table);
112 });
113
114 $schema->deploy; # do not remove, this fires the is() test in the callback above
115 ok($deploy_hook_called, 'deploy hook got called');
c66a805 @rafl Make sure overriding deployment_statements is possible from within sc…
rafl authored
116 ok($custom_deployment_statements_called, '->deploy used the schemas deploy_statements method');
427c408 @rafl Make sure we actually run all tests, given we're using done_testing.
rafl authored
117 }
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
118
119
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
120 my $translator = SQL::Translator->new(
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
121 parser_args => {
052a832 @ribasushi Make $SIG{__WARN__} overrides more Carp::Always friendly
ribasushi authored
122 dbic_schema => $schema,
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
123 },
124 producer_args => {},
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
125 );
126
052a832 @ribasushi Make $SIG{__WARN__} overrides more Carp::Always friendly
ribasushi authored
127 warnings_exist {
e377d72 @ribasushi - Allow explicit specification of ON DELETE/ON UPDATE constraints whe…
ribasushi authored
128 my $relinfo = $schema->source('Artist')->relationship_info ('cds');
129 local $relinfo->{attrs}{on_delete} = 'restrict';
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
130
e377d72 @ribasushi - Allow explicit specification of ON DELETE/ON UPDATE constraints whe…
ribasushi authored
131 $translator->parser('SQL::Translator::Parser::DBIx::Class');
132 $translator->producer('SQLite');
256e87b @ashb Fixed ningu's typo from rev 2929, and added test to catch error better
ashb authored
133
e377d72 @ribasushi - Allow explicit specification of ON DELETE/ON UPDATE constraints whe…
ribasushi authored
134 my $output = $translator->translate();
135
136 ok($output, "SQLT produced someoutput")
137 or diag($translator->error);
138
052a832 @ribasushi Make $SIG{__WARN__} overrides more Carp::Always friendly
ribasushi authored
139 } [
140 (qr/SQLT attribute .+? was supplied for relationship .+? which does not appear to be a foreign constraint/) x 2
141 ], 'Warn about dubious on_delete/on_update attributes';
256e87b @ashb Fixed ningu's typo from rev 2929, and added test to catch error better
ashb authored
142
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
143 # Note that the constraints listed here are the only ones that are tested -- if
144 # more exist in the Schema than are listed here and all listed constraints are
c75b18e cleared up docs a bit in 86sqlt.t
Justin Guenther authored
145 # correct, the test will still pass. If you add a class with UNIQUE or FOREIGN
146 # KEY constraints to DBICTest::Schema, add tests here if you think the existing
147 # test coverage is not sufficient
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
148
149 my %fk_constraints = (
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
150
151 # TwoKeys
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
152 twokeys => [
153 {
154 'display' => 'twokeys->cd',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
155 'name' => 'twokeys_fk_cd', 'index_name' => 'twokeys_idx_cd',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
156 'selftable' => 'twokeys', 'foreigntable' => 'cd',
157 'selfcols' => ['cd'], 'foreigncols' => ['cdid'],
9c1f796 @lukesaunders fixed failing test
lukesaunders authored
158 'noindex' => 1,
13de943 @ashb is_deferrable patch from Debolaz
ashb authored
159 on_delete => '', on_update => '', deferrable => 0,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
160 },
161 {
162 'display' => 'twokeys->artist',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
163 'name' => 'twokeys_fk_artist', 'index_name' => 'twokeys_idx_artist',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
164 'selftable' => 'twokeys', 'foreigntable' => 'artist',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
165 'selfcols' => ['artist'], 'foreigncols' => ['artistid'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
166 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
167 },
168 ],
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
169
170 # FourKeys_to_TwoKeys
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
171 fourkeys_to_twokeys => [
172 {
173 'display' => 'fourkeys_to_twokeys->twokeys',
f34cb1f @jjn1056 fixed failing test for sqlt
jjn1056 authored
174 'name' => 'fourkeys_to_twokeys_fk_t_artist_t_cd', 'index_name' => 'fourkeys_to_twokeys_idx_t_artist_t_cd',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
175 'selftable' => 'fourkeys_to_twokeys', 'foreigntable' => 'twokeys',
176 'selfcols' => ['t_artist', 't_cd'], 'foreigncols' => ['artist', 'cd'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
177 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
178 },
179 {
f34cb1f @jjn1056 fixed failing test for sqlt
jjn1056 authored
180 'display' => 'fourkeys_to_twokeys->fourkeys', 'index_name' => 'fourkeys_to_twokeys_idx_f_foo_f_bar_f_hello_f_goodbye',
d1b264d @jjn1056 changed SQLT::Parser::DBIC so that in FK constraints, both the field …
jjn1056 authored
181 'name' => 'fourkeys_to_twokeys_fk_f_foo_f_bar_f_hello_f_goodbye',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
182 'selftable' => 'fourkeys_to_twokeys', 'foreigntable' => 'fourkeys',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
183 'selfcols' => [qw(f_foo f_bar f_hello f_goodbye)],
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
184 'foreigncols' => [qw(foo bar hello goodbye)],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
185 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
186 },
187 ],
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
188
189 # CD_to_Producer
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
190 cd_to_producer => [
191 {
192 'display' => 'cd_to_producer->cd',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
193 'name' => 'cd_to_producer_fk_cd', 'index_name' => 'cd_to_producer_idx_cd',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
194 'selftable' => 'cd_to_producer', 'foreigntable' => 'cd',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
195 'selfcols' => ['cd'], 'foreigncols' => ['cdid'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
196 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
197 },
198 {
199 'display' => 'cd_to_producer->producer',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
200 'name' => 'cd_to_producer_fk_producer', 'index_name' => 'cd_to_producer_idx_producer',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
201 'selftable' => 'cd_to_producer', 'foreigntable' => 'producer',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
202 'selfcols' => ['producer'], 'foreigncols' => ['producerid'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
203 on_delete => '', on_update => '', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
204 },
205 ],
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
206
207 # Self_ref_alias
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
208 self_ref_alias => [
209 {
210 'display' => 'self_ref_alias->self_ref for self_ref',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
211 'name' => 'self_ref_alias_fk_self_ref', 'index_name' => 'self_ref_alias_idx_self_ref',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
212 'selftable' => 'self_ref_alias', 'foreigntable' => 'self_ref',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
213 'selfcols' => ['self_ref'], 'foreigncols' => ['id'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
214 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
215 },
216 {
217 'display' => 'self_ref_alias->self_ref for alias',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
218 'name' => 'self_ref_alias_fk_alias', 'index_name' => 'self_ref_alias_idx_alias',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
219 'selftable' => 'self_ref_alias', 'foreigntable' => 'self_ref',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
220 'selfcols' => ['alias'], 'foreigncols' => ['id'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
221 on_delete => '', on_update => '', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
222 },
223 ],
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
224
225 # CD
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
226 cd => [
227 {
228 'display' => 'cd->artist',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
229 'name' => 'cd_fk_artist', 'index_name' => 'cd_idx_artist',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
230 'selftable' => 'cd', 'foreigntable' => 'artist',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
231 'selfcols' => ['artist'], 'foreigncols' => ['artistid'],
a0dd867 @ribasushi Some testdb changes and alignment, preparing for test refactor branch
ribasushi authored
232 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
233 },
234 ],
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
235
236 # Artist_undirected_map
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
237 artist_undirected_map => [
238 {
239 'display' => 'artist_undirected_map->artist for id1',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
240 'name' => 'artist_undirected_map_fk_id1', 'index_name' => 'artist_undirected_map_idx_id1',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
241 'selftable' => 'artist_undirected_map', 'foreigntable' => 'artist',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
242 'selfcols' => ['id1'], 'foreigncols' => ['artistid'],
e377d72 @ribasushi - Allow explicit specification of ON DELETE/ON UPDATE constraints whe…
ribasushi authored
243 on_delete => 'RESTRICT', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
244 },
245 {
246 'display' => 'artist_undirected_map->artist for id2',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
247 'name' => 'artist_undirected_map_fk_id2', 'index_name' => 'artist_undirected_map_idx_id2',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
248 'selftable' => 'artist_undirected_map', 'foreigntable' => 'artist',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
249 'selfcols' => ['id2'], 'foreigncols' => ['artistid'],
b230b4b @ribasushi Minor cleanups
ribasushi authored
250 on_delete => '', on_update => '', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
251 },
252 ],
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
253
254 # Track
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
255 track => [
256 {
257 'display' => 'track->cd',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
258 'name' => 'track_fk_cd', 'index_name' => 'track_idx_cd',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
259 'selftable' => 'track', 'foreigntable' => 'cd',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
260 'selfcols' => ['cd'], 'foreigncols' => ['cdid'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
261 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
262 },
263 ],
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
264
265 # TreeLike
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
266 treelike => [
267 {
268 'display' => 'treelike->treelike for parent',
61177e4 @jjn1056 reverted unneeded change to field name in Treelike.pm to parent from …
jjn1056 authored
269 'name' => 'treelike_fk_parent', 'index_name' => 'treelike_idx_parent',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
270 'selftable' => 'treelike', 'foreigntable' => 'treelike',
61177e4 @jjn1056 reverted unneeded change to field name in Treelike.pm to parent from …
jjn1056 authored
271 'selfcols' => ['parent'], 'foreigncols' => ['id'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
272 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
273 },
274 ],
275
276 # TwoKeyTreeLike
277 twokeytreelike => [
278 {
279 'display' => 'twokeytreelike->twokeytreelike for parent1,parent2',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
280 'name' => 'twokeytreelike_fk_parent1_parent2', 'index_name' => 'twokeytreelike_idx_parent1_parent2',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
281 'selftable' => 'twokeytreelike', 'foreigntable' => 'twokeytreelike',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
282 'selfcols' => ['parent1', 'parent2'], 'foreigncols' => ['id1','id2'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
283 on_delete => '', on_update => '', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
284 },
285 ],
ae51573 Incorporate changes in -current.
Aran Deltac authored
286
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
287 # Tags
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
288 tags => [
289 {
290 'display' => 'tags->cd',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
291 'name' => 'tags_fk_cd', 'index_name' => 'tags_idx_cd',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
292 'selftable' => 'tags', 'foreigntable' => 'cd',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
293 'selfcols' => ['cd'], 'foreigncols' => ['cdid'],
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
294 on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
295 },
296 ],
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
297
298 # Bookmark
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
299 bookmark => [
300 {
301 'display' => 'bookmark->link',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
302 'name' => 'bookmark_fk_link', 'index_name' => 'bookmark_idx_link',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
303 'selftable' => 'bookmark', 'foreigntable' => 'link',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
304 'selfcols' => ['link'], 'foreigncols' => ['id'],
def17c5 @ribasushi Fix find_or_new/create to stop returning random rows when default val…
ribasushi authored
305 on_delete => 'SET NULL', on_update => 'CASCADE', deferrable => 1,
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
306 },
307 ],
a002465 @ashb Fix is_foreign_key_constraint - thanks Jon Schutz
ashb authored
308 # ForceForeign
309 forceforeign => [
310 {
311 'display' => 'forceforeign->artist',
bb0f01d @shadowcat-mst fix SQL::Translator parser to add $table_idx_ on the front of index n…
shadowcat-mst authored
312 'name' => 'forceforeign_fk_artist', 'index_name' => 'forceforeign_idx_artist',
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
313 'selftable' => 'forceforeign', 'foreigntable' => 'artist',
314 'selfcols' => ['artist'], 'foreigncols' => ['artistid'],
827a808 @abraxxa fixed Authors section
abraxxa authored
315 'noindex' => 1,
e394339 @ashb Fix test to reflect correct default state for deferrable constraints …
ashb authored
316 on_delete => '', on_update => '', deferrable => 1,
a002465 @ashb Fix is_foreign_key_constraint - thanks Jon Schutz
ashb authored
317 },
318 ],
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
319 );
320
321 my %unique_constraints = (
322 # CD
323 cd => [
324 {
325 'display' => 'cd artist and title unique',
0da8b7d @ashb Constraint/index name fix from rdj
ashb authored
326 'name' => 'cd_artist_title',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
327 'table' => 'cd', 'cols' => ['artist', 'title'],
328 },
329 ],
330
331 # Producer
332 producer => [
333 {
334 'display' => 'producer name unique',
0da8b7d @ashb Constraint/index name fix from rdj
ashb authored
335 'name' => 'prod_name', # explicit name
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
336 'table' => 'producer', 'cols' => ['name'],
337 },
338 ],
339
340 # TwoKeyTreeLike
341 twokeytreelike => [
342 {
343 'display' => 'twokeytreelike name unique',
0da8b7d @ashb Constraint/index name fix from rdj
ashb authored
344 'name' => 'tktlnameunique', # explicit name
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
345 'table' => 'twokeytreelike', 'cols' => ['name'],
346 },
347 ],
348
349 # Employee
350 # Constraint is commented out in DBICTest/Schema/Employee.pm
351 # employee => [
352 # {
353 # 'display' => 'employee position and group_id unique',
0da8b7d @ashb Constraint/index name fix from rdj
ashb authored
354 # 'name' => 'position_group',
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
355 # 'table' => 'employee', cols => ['position', 'group_id'],
356 # },
357 # ],
7b90bb1 Added support for unique constraints to SQLT::Parser::DBIx::Class
Stephan Szabo authored
358 );
359
17cab2f @ashb s/indices/indexes/ to keep Jess happy.
ashb authored
360 my %indexes = (
c385ece @ashb Add an add_index method on ResultSource (and proxy classes)
ashb authored
361 artist => [
362 {
363 'fields' => ['name']
364 },
f89bb83 @nothingmuch Add sqlt_deploy_hook to Result Source
nothingmuch authored
365 ],
366 track => [
367 {
368 'fields' => ['title']
369 }
370 ],
c385ece @ashb Add an add_index method on ResultSource (and proxy classes)
ashb authored
371 );
372
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
373 my $tschema = $translator->schema();
d6c79cb @ashb Test sqlt_deploy_hook on the Schema level
ashb authored
374 # Test that the $schema->sqlt_deploy_hook was called okay and that it removed
458e029 @ribasushi Various fixes to make testing with DBICTEST_SQLT_DEPLOY=1 possible
ribasushi authored
375 # the 'dummy' table
376 ok( !defined($tschema->get_table('dummy')), "Dummy table was removed by hook");
d6c79cb @ashb Test sqlt_deploy_hook on the Schema level
ashb authored
377
1f5bf32 @ribasushi Some forgotten tests
ribasushi authored
378 # Test that the Artist resultsource sqlt_deploy_hook was called okay and added
379 # an index
380 SKIP: {
381 skip ('Artist sqlt_deploy_hook is only called with an SQLite backend', 1)
382 if $schema->storage->sqlt_type ne 'SQLite';
383
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
384 ok( ( grep
1f5bf32 @ribasushi Some forgotten tests
ribasushi authored
385 { $_->name eq 'artist_name_hookidx' }
386 $tschema->get_table('artist')->get_indices
387 ), 'sqlt_deploy_hook fired within a resultsource');
388 }
389
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
390 # Test that nonexistent constraints are not found
391 my $constraint = get_constraint('FOREIGN KEY', 'cd', ['title'], 'cd', ['year']);
392 ok( !defined($constraint), 'nonexistent FOREIGN KEY constraint not found' );
393 $constraint = get_constraint('UNIQUE', 'cd', ['artist']);
394 ok( !defined($constraint), 'nonexistent UNIQUE constraint not found' );
a002465 @ashb Fix is_foreign_key_constraint - thanks Jon Schutz
ashb authored
395 $constraint = get_constraint('FOREIGN KEY', 'forceforeign', ['cd'], 'cd', ['cdid']);
396 ok( !defined($constraint), 'forced nonexistent FOREIGN KEY constraint not found' );
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
397
398 for my $expected_constraints (keys %fk_constraints) {
399 for my $expected_constraint (@{ $fk_constraints{$expected_constraints} }) {
400 my $desc = $expected_constraint->{display};
401 my $constraint = get_constraint(
402 'FOREIGN KEY',
403 $expected_constraint->{selftable}, $expected_constraint->{selfcols},
404 $expected_constraint->{foreigntable}, $expected_constraint->{foreigncols},
405 );
406 ok( defined($constraint), "FOREIGN KEY constraint matching `$desc' found" );
407 test_fk($expected_constraint, $constraint);
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
408 }
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
409 }
410
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
411 for my $expected_constraints (keys %unique_constraints) {
412 for my $expected_constraint (@{ $unique_constraints{$expected_constraints} }) {
413 my $desc = $expected_constraint->{display};
414 my $constraint = get_constraint(
415 'UNIQUE', $expected_constraint->{table}, $expected_constraint->{cols},
416 );
417 ok( defined($constraint), "UNIQUE constraint matching `$desc' found" );
0da8b7d @ashb Constraint/index name fix from rdj
ashb authored
418 test_unique($expected_constraint, $constraint);
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
419 }
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
420 }
421
17cab2f @ashb s/indices/indexes/ to keep Jess happy.
ashb authored
422 for my $table_index (keys %indexes) {
423 for my $expected_index ( @{ $indexes{$table_index} } ) {
c385ece @ashb Add an add_index method on ResultSource (and proxy classes)
ashb authored
424 ok ( get_index($table_index, $expected_index), "Got a matching index on $table_index table");
425 }
426 }
427
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
428 # Returns the Constraint object for the specified constraint type, table and
429 # columns from the SQL::Translator schema, or undef if no matching constraint
430 # is found.
431 #
432 # NB: $type is either 'FOREIGN KEY' or 'UNIQUE'. In UNIQUE constraints the last
433 # two parameters are not used.
434 sub get_constraint {
435 my ($type, $table_name, $cols, $f_table, $f_cols) = @_;
436 $f_table ||= ''; # For UNIQUE constraints, reference_table is ''
437 $f_cols ||= [];
438
439 my $table = $tschema->get_table($table_name);
440
441 my %fields = map { $_ => 1 } @$cols;
442 my %f_fields = map { $_ => 1 } @$f_cols;
443
a7e65bb @ashb Remove the length limit on identifiers - it doesn't belong in DBIx::C…
ashb authored
444 die "No $table_name" unless $table;
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
445 CONSTRAINT:
446 for my $constraint ( $table->get_constraints ) {
447 next unless $constraint->type eq $type;
448 next unless $constraint->reference_table eq $f_table;
449
450 my %rev_fields = map { $_ => 1 } $constraint->fields;
451 my %rev_f_fields = map { $_ => 1 } $constraint->reference_fields;
452
453 # Check that the given fields are a subset of the constraint's fields
454 for my $field ($constraint->fields) {
455 next CONSTRAINT unless $fields{$field};
456 }
457 if ($type eq 'FOREIGN KEY') {
458 for my $f_field ($constraint->reference_fields) {
459 next CONSTRAINT unless $f_fields{$f_field};
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
460 }
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
461 }
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
462
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
463 # Check that the constraint's fields are a subset of the given fields
464 for my $field (@$cols) {
465 next CONSTRAINT unless $rev_fields{$field};
466 }
467 if ($type eq 'FOREIGN KEY') {
468 for my $f_field (@$f_cols) {
469 next CONSTRAINT unless $rev_f_fields{$f_field};
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
470 }
471 }
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
472
473 return $constraint; # everything passes, found the constraint
661fc8e fixed up sqlt tests a bit and tried fixing 2 failing sqlt tests
Justin Guenther authored
474 }
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
475 return undef; # didn't find a matching constraint
7b90bb1 Added support for unique constraints to SQLT::Parser::DBIx::Class
Stephan Szabo authored
476 }
477
c385ece @ashb Add an add_index method on ResultSource (and proxy classes)
ashb authored
478 sub get_index {
479 my ($table_name, $index) = @_;
480
481 my $table = $tschema->get_table($table_name);
482
483 CAND_INDEX:
484 for my $cand_index ( $table->get_indices ) {
8273e84 @ribasushi Trailing WS crusade - got to save them bits
ribasushi authored
485
c385ece @ashb Add an add_index method on ResultSource (and proxy classes)
ashb authored
486 next CAND_INDEX if $index->{name} && $cand_index->name ne $index->{name}
487 || $index->{type} && $cand_index->type ne $index->{type};
488
489 my %idx_fields = map { $_ => 1 } $cand_index->fields;
490
491 for my $field ( @{ $index->{fields} } ) {
492 next CAND_INDEX unless $idx_fields{$field};
493 }
494
495 %idx_fields = map { $_ => 1 } @{$index->{fields}};
496 for my $field ( $cand_index->fields) {
497 next CAND_INDEX unless $idx_fields{$field};
498 }
499
500 return $cand_index;
501 }
502
503 return undef; # No matching idx
504 }
505
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
506 # Test parameters in a FOREIGN KEY constraint other than columns
507 sub test_fk {
508 my ($expected, $got) = @_;
509 my $desc = $expected->{display};
0da8b7d @ashb Constraint/index name fix from rdj
ashb authored
510 is( $got->name, $expected->{name},
827a808 @abraxxa fixed Authors section
abraxxa authored
511 "name parameter correct for '$desc'" );
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
512 is( $got->on_delete, $expected->{on_delete},
827a808 @abraxxa fixed Authors section
abraxxa authored
513 "on_delete parameter correct for '$desc'" );
b1edf9f refactored SQL::Translator tests to only test certain constraints, an…
Justin Guenther authored
514 is( $got->on_update, $expected->{on_update},
827a808 @abraxxa fixed Authors section
abraxxa authored
515 "on_update parameter correct for '$desc'" );
13de943 @ashb is_deferrable patch from Debolaz
ashb authored
516 is( $got->deferrable, $expected->{deferrable},
827a808 @abraxxa fixed Authors section
abraxxa authored
517 "is_deferrable parameter correct for '$desc'" );
0da8b7d @ashb Constraint/index name fix from rdj
ashb authored
518
519 my $index = get_index( $got->table, { fields => $expected->{selfcols} } );
9c1f796 @lukesaunders fixed failing test
lukesaunders authored
520
521 if ($expected->{noindex}) {
827a808 @abraxxa fixed Authors section
abraxxa authored
522 ok( !defined $index, "index doesn't for '$desc'" );
9c1f796 @lukesaunders fixed failing test
lukesaunders authored
523 } else {
827a808 @abraxxa fixed Authors section
abraxxa authored
524 ok( defined $index, "index exists for '$desc'" );
525 is( $index->name, $expected->{index_name}, "index has correct name for '$desc'" );
9c1f796 @lukesaunders fixed failing test
lukesaunders authored
526 }
0da8b7d @ashb Constraint/index name fix from rdj
ashb authored
527 }
528
529 sub test_unique {
530 my ($expected, $got) = @_;
531 my $desc = $expected->{display};
532 is( $got->name, $expected->{name},
827a808 @abraxxa fixed Authors section
abraxxa authored
533 "name parameter correct for '$desc'" );
637ca93 Changed logic for determining foreign key constraints
Stephan Szabo authored
534 }
0fd7e9a @ribasushi Fix a weird-ass sqlt invocation in deployment_statements()
ribasushi authored
535
536 done_testing;
Something went wrong with that request. Please try again.