blib/lib/DBIO/Test/Conformance/Cases/DDL.pm

filter: Statementstmt 100% 21 / 21 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 32 / 32 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/DBIO/Test/Conformance/Cases/Bind.pm ↑ Summary blib/lib/DBIO/Test/Conformance/Cases/Names.pm »
1 package DBIO::Test::Conformance::Cases::DDL;
2 # ABSTRACT: The shared DDL cases every DBIO driver answers
3  
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 our $VERSION = '0.900007';
8  
9 7 ▶use DBIO::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use DBIO::Schema::Type ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 161 ▶my $id = sub { +{ data_type => 'integer', is_nullable => 0 } };
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 my @CASES = (
16  
17 {
18 name => 'ddl-default-string-apostrophe',
19 since => 1,
20 subject => { source => 'Note', column => 'note' },
21 input => { sources => [ {
22 name => 'Note', table => 'note',
23 columns => [
24 id => $id->(),
25 note => { data_type => 'varchar', size => 20, is_nullable => 0,
26 default_value => "it's" },
27 ],
28 primary_key => [ 'id' ],
29 } ] },
30 expect => [
31 { read_back => { source => 'Note', create => { id => 1 },
32 is => { note => "it's" } } },
33 ],
34 },
35  
36 {
37 name => 'ddl-default-digit-string',
38 since => 1,
39 subject => { source => 'Code', column => 'code' },
40 input => { sources => [ {
41 name => 'Code', table => 'code',
42 columns => [
43 id => $id->(),
44 code => { data_type => 'char', size => 5, is_nullable => 0,
45 default_value => '007' },
46 ],
47 primary_key => [ 'id' ],
48 } ] },
49 expect => [
50 { read_back => { source => 'Code', create => { id => 1 },
51 is => { code => '007' } } },
52 ],
53 },
54  
55 {
56 name => 'ddl-default-expression',
57 since => 1,
58 subject => { source => 'Stamp', column => 'created' },
59 input => { sources => [ {
60 name => 'Stamp', table => 'stamp',
61 columns => [
62 id => $id->(),
63 created => { data_type => 'timestamp', is_nullable => 0,
64 default_value => \'CURRENT_TIMESTAMP' },
65 ],
66 primary_key => [ 'id' ],
67 } ] },
68 expect => [
69 { read_back => { source => 'Stamp', create => { id => 1 },
70 like => { created => qr/^\d{4}-\d\d-\d\d/ },
71 isnt => { created => 'CURRENT_TIMESTAMP' } } },
72 ],
73 },
74  
75 {
76 name => 'ddl-enum-value-apostrophe',
77 since => 1,
78 subject => { source => 'Pick', column => 'kind' },
79 input => { sources => [ {
80 name => 'Pick', table => 'pick',
81 columns => [
82 id => $id->(),
83 kind => { data_type => 'enum', extra => { list => [ "it's", 'plain' ] },
84 is_nullable => 0 },
85 ],
86 primary_key => [ 'id' ],
87 } ] },
88 expect => [
89 { read_back => { source => 'Pick', create => { id => 1, kind => "it's" },
90 is => { kind => "it's" } } },
91 ],
92 },
93  
94 {
95 name => 'ddl-ident-reserved-word',
96 since => 1,
97 subject => { source => 'Order', column => 'group' },
98 input => { sources => [ {
99 name => 'Order', table => 'order',
100 columns => [
101 id => $id->(),
102 user => { data_type => 'varchar', size => 20, is_nullable => 1 },
103 group => { data_type => 'varchar', size => 20, is_nullable => 1 },
104 end => { data_type => 'varchar', size => 20, is_nullable => 1 },
105 ],
106 primary_key => [ 'id' ],
107 } ] },
108 expect => [
109 { read_back => { source => 'Order',
110 create => { id => 1, user => 'u', group => 'g', end => 'e' },
111 is => { user => 'u', group => 'g', end => 'e' } } },
112 { search_by => { source => 'Order', create => { id => 2, user => 'v', group => 'h', end => 'f' },
113 column => 'group', value => 'h' } },
114 ],
115 },
116  
117 {
118 name => 'ddl-ident-mixed-case',
119 since => 1,
120 subject => { source => 'MixedCase', column => 'camelCol' },
121 input => { sources => [ {
122 name => 'MixedCase', table => 'MixedCase',
123 columns => [
124 id => $id->(),
125 camelCol => { data_type => 'varchar', size => 20, is_nullable => 1 },
126 ],
127 primary_key => [ 'id' ],
128 } ] },
129 expect => [
130 { fact => { name => 'table_name', source => 'MixedCase', is => 'MixedCase' } },
131 { fact => { name => 'column_names', source => 'MixedCase',
132 is => [ 'camelCol', 'id' ] } },
133 ],
134 },
135  
136 {
137 name => 'ddl-ident-special-chars',
138 since => 1,
139 subject => { source => 'Odd', column => 'odd "c" `n`' },
140 input => { sources => [ {
141 name => 'Odd', table => 'odd "t" `n`',
142 columns => [
143 id => $id->(),
144 'odd "c" `n`' => { data_type => 'varchar', size => 20, is_nullable => 1,
145 accessor => 'odd_c' },
146 ],
147 primary_key => [ 'id' ],
148 } ] },
149 expect => [
150 { fact => { name => 'table_name', source => 'Odd', is => 'odd "t" `n`' } },
151 { fact => { name => 'column_names', source => 'Odd',
152 is => [ 'id', 'odd "c" `n`' ] } },
153 { read_back => { source => 'Odd', create => { id => 1, 'odd "c" `n`' => 'x' },
154 is => { 'odd "c" `n`' => 'x' } } },
155 ],
156 },
157  
158 {
159 name => 'ddl-view-declared',
160 since => 1,
161 subject => { source => 'BaseView' },
162 input => { sources => [
163 {
164 name => 'Base', table => 'base',
165 columns => [
166 id => $id->(),
167 name => { data_type => 'varchar', size => 20, is_nullable => 1 },
168 ],
169 primary_key => [ 'id' ],
170 },
171 {
172 name => 'BaseView', table => 'base_view',
173 columns => [
174 id => { data_type => 'integer' },
175 name => { data_type => 'varchar', size => 20 },
176 ],
177 view => { definition => 'SELECT {{id}}, {{name}} FROM {{base}}', virtual => 0 },
178 },
179 {
180 name => 'VirtualView', table => 'virtual_view',
181 columns => [
182 id => { data_type => 'integer' },
183 ],
184 view => { definition => 'SELECT id FROM base', virtual => 1 },
185 },
186 ] },
187 expect => [
188 { fact => { name => 'object_kind', source => 'BaseView', is => 'view' } },
189 { fact => { name => 'object_kind', source => 'VirtualView', is => undef } },
190 { search_by => { source => 'Base', create => { id => 1, name => 'x' },
191 through => 'BaseView', column => 'name', value => 'x' } },
192 ],
193 },
194  
195 {
196 name => 'ddl-unique-constraint',
197 since => 1,
198 subject => { source => 'Pair', column => 'a' },
199 input => { sources => [ {
200 name => 'Pair', table => 'pair',
201 columns => [
202 id => $id->(),
203 a => { data_type => 'integer', is_nullable => 0 },
204 b => { data_type => 'integer', is_nullable => 0 },
205 ],
206 primary_key => [ 'id' ],
207 unique => [ [ pair_ab => [ 'a', 'b' ] ] ],
208 } ] },
209 expect => [
210 { fact => { name => 'unique_exists', source => 'Pair', columns => [ 'a', 'b' ], is => 1 } },
211 { rejects => { source => 'Pair', first => { id => 1, a => 1, b => 2 },
212 create => { id => 2, a => 1, b => 2 } } },
213 ],
214 },
215  
216 {
217 name => 'ddl-foreign-key',
218 since => 1,
219 subject => { source => 'Child', column => 'parent_id' },
220 input => { sources => [
221 {
222 name => 'Parent', table => 'parent',
223 columns => [ id => $id->() ],
224 primary_key => [ 'id' ],
225 },
226 {
227 name => 'Child', table => 'child',
228 columns => [
229 id => $id->(),
230 parent_id => { data_type => 'integer', is_nullable => 0 },
231 ],
232 primary_key => [ 'id' ],
233 relationships => [
234 { type => 'belongs_to', name => 'parent', source => 'Parent', cond => 'parent_id' },
235 ],
236 },
237 ] },
238 expect => [
239 { fact => { name => 'foreign_key_count', source => 'Child', is => 1 } },
240 { rejects => { source => 'Child', create => { id => 1, parent_id => 999 } } },
241 ],
242 },
243  
244 {
245 name => 'ddl-fk-actions',
246 since => 1,
247 subject => { source => 'Child', column => 'parent_id' },
248 input => { sources => [
249 {
250 name => 'Parent', table => 'parent',
251 columns => [ id => $id->() ],
252 primary_key => [ 'id' ],
253 },
254 {
255 name => 'Child', table => 'child',
256 columns => [
257 id => $id->(),
258 parent_id => { data_type => 'integer', is_nullable => 0 },
259 ],
260 primary_key => [ 'id' ],
261 relationships => [
262 { type => 'belongs_to', name => 'parent', source => 'Parent',
263 cond => 'parent_id', attrs => { on_delete => 'CASCADE' } },
264 ],
265 },
266 ] },
267 expect => [
268 { cascade_delete => { parent => 'Parent', parent_values => { id => 1 },
269 child => 'Child', child_values => { id => 1 },
270 link => { parent_id => 'id' } } },
271 ],
272 },
273  
274 {
275 name => 'ddl-fk-two-rels-one-column',
276 since => 1,
277 subject => { source => 'Child', column => 'parent_id' },
278 input => { sources => [
279 {
280 name => 'Parent', table => 'parent',
281 columns => [ id => $id->() ],
282 primary_key => [ 'id' ],
283 },
284 {
285 name => 'Child', table => 'child',
286 columns => [
287 id => $id->(),
288 parent_id => { data_type => 'integer', is_nullable => 0 },
289 ],
290 primary_key => [ 'id' ],
291 relationships => [
292 { type => 'belongs_to', name => 'parent', source => 'Parent', cond => 'parent_id' },
293 { type => 'belongs_to', name => 'parent_alt', source => 'Parent', cond => 'parent_id' },
294 ],
295 },
296 ] },
297 expect => [
298 { fact => { name => 'foreign_key_count', source => 'Child', is => 1 } },
299 ],
300 },
301  
302 {
303 name => 'ddl-fk-table-order',
304 since => 1,
305 subject => { source => 'AChild', column => 'parent_id' },
306 input => { sources => [
307 {
308 name => 'AChild', table => 'a_child',
309 columns => [
310 id => $id->(),
311 parent_id => { data_type => 'integer', is_nullable => 0 },
312 ],
313 primary_key => [ 'id' ],
314 relationships => [
315 { type => 'belongs_to', name => 'parent', source => 'ZParent', cond => 'parent_id' },
316 ],
317 },
318 {
319 name => 'ZParent', table => 'z_parent',
320 columns => [ id => $id->() ],
321 primary_key => [ 'id' ],
322 },
323 ] },
324 expect => [
325 { fact => { name => 'object_kind', source => 'AChild', is => 'table' } },
326 { fact => { name => 'foreign_key_count', source => 'AChild', is => 1 } },
327 ],
328 },
329  
330 {
331 name => 'ddl-auto-increment',
332 since => 1,
333 subject => { source => 'Counter', column => 'id' },
334 input => { sources => [ {
335 name => 'Counter', table => 'counter',
336 columns => [
337 id => { data_type => 'integer', is_auto_increment => 1, is_nullable => 0 },
338 name => { data_type => 'varchar', size => 20, is_nullable => 1 },
339 ],
340 primary_key => [ 'id' ],
341 } ] },
342 expect => [
343 { auto_key => { source => 'Counter', create => { name => 'x' } } },
344 { fact => { name => 'column_auto_increment', source => 'Counter',
345 column => 'id', is => 1 } },
346 ],
347 },
348  
349 {
350 name => 'ddl-type-size-char',
351 since => 2,
352 subject => { source => 'Sized', column => 'c' },
353 input => { sources => [ {
354 name => 'Sized', table => 'sized',
355 columns => [
356 id => $id->(),
357 c => { data_type => 'character', size => 10, is_nullable => 1 },
358 ],
359 primary_key => [ 'id' ],
360 } ] },
361 expect => [
362 { fact => { name => 'column_size', source => 'Sized', column => 'c', is => 10 } },
363 { rejects => { source => 'Sized', create => { id => 1, c => 'x' x 11 } } },
364 ],
365 },
366  
367 {
368 name => 'ddl-type-size-bit',
369 since => 2,
370 subject => { source => 'Sized', column => 'b' },
371 input => { sources => [ {
372 name => 'Sized', table => 'sized',
373 columns => [
374 id => $id->(),
375 b => { data_type => 'bit', size => 8, is_nullable => 1 },
376 ],
377 primary_key => [ 'id' ],
378 } ] },
379 expect => [
380 { fact => { name => 'column_size', source => 'Sized', column => 'b', is => 8 } },
381 ],
382 },
383  
384 {
385 name => 'ddl-base-types-roundtrip',
386 since => 1,
387 subject => { source => 'Types' },
388 input => { sources => [ {
389 name => 'Types', table => 'types',
390 columns => [
391 id => $id->(),
392 ( map {
393 56 my $type = $_;
394 56 ▶ ( "t_$type" => {
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'char' ? : 7 49 56
$type eq 'numeric' ? : 7 49 56
395 data_type => $type,
396 is_nullable => 1,
397 ( $type eq 'char' ? ( size => 5 ) : () ),
398 ( $type eq 'numeric' ? ( size => [ 10, 2 ] ) : () ),
399 } );
400 } DBIO::Schema::Type::base_types() ),
401 ],
402 primary_key => [ 'id' ],
403 } ] },
404 expect => [
405 { fact => { name => 'object_kind', source => 'Types', is => 'table' } },
406 { fact => { name => 'column_names', source => 'Types',
407 7 is => [ 'id', map { "t_$_" } DBIO::Schema::Type::base_types() ] } },
408 ],
409 },
410  
411 {
412 name => 'ddl-index-on-unique-columns',
413 since => 1,
414 subject => { source => 'Child', column => 'a' },
415 input => { sources => [
416 {
417 name => 'Parent', table => 'parent',
418 columns => [ id => $id->() ],
419 primary_key => [ 'id' ],
420 },
421 {
422 name => 'Child', table => 'child',
423 columns => [
424 id => $id->(),
425 parent_id => { data_type => 'integer', is_nullable => 0 },
426 a => { data_type => 'integer', is_nullable => 0 },
427 b => { data_type => 'integer', is_nullable => 0 },
428 ],
429 primary_key => [ 'id' ],
430 unique => [ [ child_ab => [ 'a', 'b' ] ] ],
431 relationships => [
432 { type => 'belongs_to', name => 'parent', source => 'Parent', cond => 'parent_id' },
433 ],
434 indexes => [
435 { name => 'child_ab_idx', columns => [ 'a', 'b' ] },
436 { name => 'child_parent_idx', columns => [ 'parent_id' ] },
437 ],
438 },
439 ] },
440 expect => [
441 { fact => { name => 'index_count', source => 'Child', columns => [ 'a', 'b' ], is => 1 } },
442 { fact => { name => 'index_count', source => 'Child', columns => [ 'parent_id' ], is => 1 } },
443 ],
444 },
445  
446 {
447 name => 'ddl-qualified-source-name',
448 since => 1,
449 subject => { source => 'Qualified' },
450 input => { sources => [ {
451 name => 'Qualified', table => 'other.t',
452 columns => [ id => $id->() ],
453 primary_key => [ 'id' ],
454 } ] },
455 expect => [
456 { fact => { name => 'table_in_namespace', source => 'Qualified',
457 namespace => 'other', unqualified => 't', is => 1 } },
458 ],
459 },
460  
461 {
462 name => 'ddl-unique-not-null-without-pk',
463 since => 1,
464 subject => { source => 'Loose', column => 'code' },
465 input => { sources => [ {
466 name => 'Loose', table => 'loose',
467 columns => [
468 code => { data_type => 'varchar', size => 20, is_nullable => 0 },
469 ],
470 unique => [ [ loose_code => [ 'code' ] ] ],
471 } ] },
472 expect => [
473 { fact => { name => 'primary_key_columns', source => 'Loose', is => [] } },
474 ],
475 },
476  
477 );
478  
479 57 ▶sub cases {
Subroutine cases: called CC=1 SCAR=0.0
Pod documented
480 57 return DBIO::Util::deep_copy([ @CASES ]);
481 }
482  
483 7 1;
484  
485 __END__
« blib/lib/DBIO/Test/Conformance/Cases/Bind.pm ↑ Summary blib/lib/DBIO/Test/Conformance/Cases/Names.pm »