Alzabo/RDBMSRules.pm

filter: Statementstmt 8.1% 18 / 221 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 8.7% 5 / 57 Podpod 84.0% 42 / 50 totaltotal 14.6% 65 / 444 CC 58 SCAR 62.6
CC
58
Cov
6%
table_sql_diff
1482.0
schema_sql_diff
210.0
schema_sql
12.0
CRAP 521.6
↑ Summary Alzabo/Create/Schema.pm »
1 package Alzabo::RDBMSRules;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Alzabo::Exceptions ( abbr => [ 'recreate_table_exception' ] );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use Class::Factory::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Params::Validate qw( validate validate_pos );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 0 ▶Params::Validate::validation_options( on_fail => sub { Alzabo::Exception::Params->throw( error => join '', @_ ) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
11  
12 11 $VERSION = 2.0;
13  
14 11 1;
15  
16 sub new
17 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
18 0 shift;
19 0 my %p = @_;
20  
21 0 eval "use Alzabo::RDBMSRules::$p{rdbms};";
22 0 ▶ Alzabo::Exception::Eval->throw( error => $@ ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
23 0 return "Alzabo::RDBMSRules::$p{rdbms}"->new(@_);
24 }
25  
26 0 ▶sub available { __PACKAGE__->subclasses }
Subroutine available: not called CC=1 SCAR=6.9
Pod documented
27  
28 # validation
29  
30 sub validate_schema_name
31 0 ▶{
Subroutine validate_schema_name: not called CC=1 SCAR=6.9
Pod documented
32 0 shift()->_virtual;
33 }
34  
35 sub validate_table_name
36 0 ▶{
Subroutine validate_table_name: not called CC=1 SCAR=6.9
Pod documented
37 0 shift()->_virtual;
38 }
39  
40 sub validate_column_name
41 0 ▶{
Subroutine validate_column_name: not called CC=1 SCAR=6.9
Pod documented
42 0 shift()->_virtual;
43 }
44  
45 sub validate_column_type
46 0 ▶{
Subroutine validate_column_type: not called CC=1 SCAR=6.9
Pod documented
47 0 shift()->_virtual;
48 }
49  
50 sub validate_column_length
51 0 ▶{
Subroutine validate_column_length: not called CC=1 SCAR=6.9
Pod documented
52 0 shift()->_virtual;
53 }
54  
55 sub validate_table_attribute
56 0 ▶{
Subroutine validate_table_attribute: not called CC=1 SCAR=6.9
Pod undocumented
57 0 shift()->_virtual;
58 }
59  
60 sub validate_column_attribute
61 0 ▶{
Subroutine validate_column_attribute: not called CC=1 SCAR=6.9
Pod documented
62 0 shift()->_virtual;
63 }
64  
65 sub validate_primary_key
66 0 ▶{
Subroutine validate_primary_key: not called CC=1 SCAR=6.9
Pod documented
67 0 shift()->_virtual;
68 }
69  
70 sub validate_sequenced_attribute
71 0 ▶{
Subroutine validate_sequenced_attribute: not called CC=1 SCAR=6.9
Pod documented
72 0 shift()->_virtual;
73 }
74  
75 sub validate_index
76 0 ▶{
Subroutine validate_index: not called CC=1 SCAR=6.9
Pod documented
77 0 shift()->_virtual;
78 }
79  
80 sub type_is_numeric
81 0 ▶{
Subroutine type_is_numeric: not called CC=2 SCAR=17.9
Pod documented
82 0 my $self = shift;
83 0 my $col = shift;
84  
85 0 ▶ return $self->type_is_integer($col) || $self->type_is_floating_point($col);
Condition0%0/3
$self->type_is_integer($col) || $self->type_is_floating_point($col)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->type_is_integer($col) || $self->type_is_floating_point($col)
$self->type_is_integer($col) $self->type_is_floating_point($col)
Truth table0%0/3
A || B
A= $self->type_is_integer($col)B= $self->type_is_floating_point($col)
ABresult
1X1
011
000
86 }
87  
88 sub type_is_integer
89 0 ▶{
Subroutine type_is_integer: not called CC=1 SCAR=6.9
Pod documented
90 0 shift()->_virtual;
91 }
92  
93 sub type_is_floating_point
94 0 ▶{
Subroutine type_is_floating_point: not called CC=1 SCAR=6.9
Pod documented
95 0 shift()->_virtual;
96 }
97  
98 sub type_is_character
99 0 ▶{
Subroutine type_is_character: not called CC=1 SCAR=6.9
Pod documented
100 0 shift()->_virtual;
101 }
102  
103 sub type_is_date
104 0 ▶{
Subroutine type_is_date: not called CC=1 SCAR=6.9
Pod documented
105 0 shift()->_virtual;
106 }
107  
108 sub type_is_datetime
109 0 ▶{
Subroutine type_is_datetime: not called CC=1 SCAR=6.9
Pod documented
110 0 shift()->_virtual;
111 }
112  
113 sub type_is_time
114 0 ▶{
Subroutine type_is_time: not called CC=1 SCAR=6.9
Pod documented
115 0 shift()->_virtual;
116 }
117  
118 sub type_is_time_interval
119 0 ▶{
Subroutine type_is_time_interval: not called CC=1 SCAR=6.9
Pod documented
120 0 shift()->_virtual;
121 }
122  
123 sub type_is_blob
124 0 ▶{
Subroutine type_is_blob: not called CC=1 SCAR=6.9
Pod undocumented
125 0 shift()->_virtual;
126 }
127  
128 sub blob_type
129 0 ▶{
Subroutine blob_type: not called CC=1 SCAR=6.9
Pod undocumented
130 0 shift()->virtual;
131 }
132  
133 # feature probing
134  
135 sub column_types
136 0 ▶{
Subroutine column_types: not called CC=1 SCAR=6.9
Pod documented
137 0 shift()->_virtual;
138 }
139  
140 sub feature
141 0 ▶{
Subroutine feature: not called CC=1 SCAR=6.9
Pod documented
142 0 return 0;
143 }
144  
145 0 ▶sub quote_identifiers { 0 }
Subroutine quote_identifiers: not called CC=1 SCAR=6.9
Pod documented
146  
147 0 ▶sub quote_identifiers_character { '' }
Subroutine quote_identifiers_character: not called CC=1 SCAR=6.9
Pod undocumented
148  
149 sub schema_attributes
150 0 ▶{
Subroutine schema_attributes: not called CC=1 SCAR=6.9
Pod undocumented
151 0 shift()->_virtual;
152 }
153  
154 sub table_attributes
155 0 ▶{
Subroutine table_attributes: not called CC=1 SCAR=6.9
Pod undocumented
156 0 shift()->_virtual;
157 }
158  
159 sub column_attributes
160 0 ▶{
Subroutine column_attributes: not called CC=1 SCAR=6.9
Pod undocumented
161 0 shift()->_virtual;
162 }
163  
164 sub schema_sql
165 0 ▶{
Subroutine schema_sql: not called CC=3 SCAR=24.8
Pod documented
166 0 my $self = shift;
167  
168 0 validate_pos( @_, { isa => 'Alzabo::Schema' } );
169  
170 0 my $schema = shift;
171  
172 0 my @sql;
173  
174 0 local $self->{state};
175  
176 0 foreach my $t ( $schema->tables )
177 {
178 0 push @sql, $self->table_sql($t);
179 }
180  
181 0 ▶ return @sql, @{ $self->{state}{deferred_sql} || [] };
Condition0%0/2
$self->{'state'}{'deferred_sql'} || []
l!l
00
MC/DC0%0/1
$self->{'state'}{'deferred_sql'} || []
$self->{'state'}{'deferred_sql'}
Truth table0%0/2
A
A= $self->{'state'}{'deferred_sql'}
Aresult
11
00
182 }
183  
184 sub table_sql
185 0 ▶{
Subroutine table_sql: not called CC=1 SCAR=6.9
Pod documented
186 0 shift()->_virtual;
187 }
188  
189 sub column_sql
190 0 ▶{
Subroutine column_sql: not called CC=1 SCAR=6.9
Pod documented
191 0 shift()->_virtual;
192 }
193  
194 sub index_sql
195 0 ▶{
Subroutine index_sql: not called CC=3 SCAR=24.8
Pod documented
196 0 my $self = shift;
197 0 my $index = shift;
198  
199 0 my $index_name = $index->id;
200 0 $index_name = $self->quote_identifiers_character . $index_name . $self->quote_identifiers_character;
201  
202 0 my $sql = 'CREATE';
203 0 ▶ $sql .= ' UNIQUE' if $index->unique;
Branch: 1 branch
BranchTrueFalseTotal
if $index->unique 0 0 0
204 0 $sql .= " INDEX $index_name ON ";
205 0 $sql .= $self->quote_identifiers_character;
206 0 $sql .= $index->table->name;
207 0 $sql .= $self->quote_identifiers_character;
208 0 $sql .= ' ( ';
209  
210 0 ▶ if ( defined $index->function )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index->function) { } 0 0 0
211 {
212 0 $sql .= $index->function;
213 }
214 else
215 {
216 $sql .=
217 ( join ', ',
218 0 map { $self->quote_identifiers_character . $_->name . $self->quote_identifiers_character }
219 $index->columns
220 );
221 }
222  
223 0 $sql .= ' )';
224  
225 0 return $sql;
226 }
227  
228 sub foreign_key_sql
229 0 ▶{
Subroutine foreign_key_sql: not called CC=1 SCAR=6.9
Pod documented
230 0 shift()->_virtual;
231 }
232  
233 sub drop_table_sql
234 0 ▶{
Subroutine drop_table_sql: not called CC=1 SCAR=6.9
Pod documented
235 0 my $self = shift;
236  
237 0 my $name = shift->name;
238 0 $name = $self->quote_identifiers_character . $name . $self->quote_identifiers_character;
239  
240 0 return "DROP TABLE $name";
241 }
242  
243 sub drop_column_sql
244 0 ▶{
Subroutine drop_column_sql: not called CC=1 SCAR=6.9
Pod documented
245 0 shift()->_virtual;
246 }
247  
248 sub drop_index_sql
249 0 ▶{
Subroutine drop_index_sql: not called CC=1 SCAR=6.9
Pod documented
250 0 shift()->_virtual;
251 }
252  
253 sub drop_foreign_key_sql
254 0 ▶{
Subroutine drop_foreign_key_sql: not called CC=1 SCAR=6.9
Pod documented
255 0 shift()->_virtual;
256 }
257  
258 sub column_sql_add
259 0 ▶{
Subroutine column_sql_add: not called CC=1 SCAR=6.9
Pod documented
260 0 shift()->_virtual;
261 }
262  
263 sub column_sql_diff
264 0 ▶{
Subroutine column_sql_diff: not called CC=1 SCAR=6.9
Pod documented
265 0 shift()->_virtual;
266 }
267  
268 sub index_sql_diff
269 0 ▶{
Subroutine index_sql_diff: not called CC=2 SCAR=17.9
Pod documented
270 0 my $self = shift;
271  
272 0 validate( @_, { new => { isa => 'Alzabo::Index' },
273 old => { isa => 'Alzabo::Index' } } );
274  
275 0 my %p = @_;
276  
277 0 my $new_sql = $self->index_sql($p{new});
278  
279 0 my @sql;
280 0 ▶ if ( $new_sql ne $self->index_sql($p{old}) )
Branch: 1 branch
BranchTrueFalseTotal
if ($new_sql ne $self->index_sql($p{"old"})) 0 0 0
281 {
282 0 push @sql, $self->drop_index_sql( $p{old}, $p{new}->table->name );
283 0 push @sql, $new_sql;
284 }
285  
286 0 return @sql;
287 }
288  
289 sub alter_primary_key_sql
290 0 ▶{
Subroutine alter_primary_key_sql: not called CC=1 SCAR=6.9
Pod documented
291 0 shift()->_virtual;
292 }
293  
294 sub can_alter_table_name
295 0 ▶{
Subroutine can_alter_table_name: not called CC=1 SCAR=6.9
Pod documented
296 0 1;
297 }
298  
299 sub can_alter_column_name
300 0 ▶{
Subroutine can_alter_column_name: not called CC=1 SCAR=6.9
Pod documented
301 0 1;
302 }
303  
304 sub alter_table_name_sql
305 0 ▶{
Subroutine alter_table_name_sql: not called CC=1 SCAR=6.9
Pod documented
306 0 shift()->_virtual;
307 }
308  
309 sub alter_column_name_sql
310 0 ▶{
Subroutine alter_column_name_sql: not called CC=1 SCAR=6.9
Pod documented
311 0 shift()->_virtual;
312 }
313  
314 sub recreate_table_sql
315 0 ▶{
Subroutine recreate_table_sql: not called CC=1 SCAR=6.9
Pod documented
316 0 shift()->_virtual;
317 }
318  
319 =pod
320  
321 sub reverse_engineer
322 {
323 my $self = shift;
324 my $schema = shift;
325  
326 my $dbh = $schema->driver->handle;
327  
328 foreach my $table ( $dbh->tables )
329 {
330 my $t = $schema->make_table( name => $table );
331  
332 $self->reverse_engineer_table($t);
333 }
334 }
335  
336 sub reverse_engineer_table
337 {
338 my $self = shift;
339 my $table = shift;
340  
341 my $dbh = $table->schema->driver->handle;
342  
343 my $sth = $dbh->column_info( undef, $table->schema->name, $table->name, undef );
344  
345 while ( my $col_info = $sth->fetchrow_hashref )
346 {
347 use Data::Dumper; warn Dumper $col_info;
348 my %attr = ( name => $col_info->{COLUMN_NAME},
349 type => $col_info->{TYPE_NAME},
350 nullable => $col_info->{NULLABLE} ? 1 : 0,
351 );
352  
353 $attr{size} =
354 $col_info->{COLUMN_SIZE} if $col_info->{COLUMN_SIZE};
355  
356 $attr{precision} =
357 $col_info->{DECIMAL_DIGITS} if $col_info->{DECIMAL_DIGITS};
358  
359 $attr{default} =
360 $col_info->{COLUMN_DEF} if defined $col_info->{COLUMN_DEF};
361  
362 $attr{comment} =
363 $col_info->{REMARKS} if defined $col_info->{REMARKS};
364  
365 $table->make_column(%attr);
366 }
367  
368 $self->reverse_engineer_table_primary_key($table);
369 }
370  
371 sub reverse_engineer_table_primary_key
372 {
373 my $self = shift;
374 my $table = shift;
375  
376 my $dbh = $table->schema->driver->handle;
377  
378 my $sth = $dbh->column_info( undef, $table->schema->name, $table->name );
379  
380 while ( my $pk_info = $sth->fetchrow_hashref )
381 {
382 $table->add_primary_key( $table->column( $pk_info->{COLUMN_NAME} ) );
383 }
384 }
385  
386 =cut
387  
388 sub rules_id
389 0 ▶{
Subroutine rules_id: not called CC=1 SCAR=6.9
Pod undocumented
390 0 shift()->_virtual;
391 }
392  
393 sub schema_sql_diff
394 0 ▶{
Subroutine schema_sql_diff: not called CC=14 SCAR=53.5
Pod documented
395 0 my $self = shift;
396  
397 0 validate( @_, { new => { isa => 'Alzabo::Schema' },
398 old => { isa => 'Alzabo::Schema' } } );
399  
400 0 my %p = @_;
401  
402 0 local $self->{state};
403  
404 0 my @sql;
405 my %changed_name;
406 0 foreach my $new_t ( $p{new}->tables )
407 {
408 # When syncing against an existing schema, the table may be
409 # present with its new name.
410 0 my $old_t;
411 0 ▶ if ( defined $new_t->former_name )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_t->former_name) 0 0 0
412 {
413 0 $old_t = eval { $p{old}->table( $new_t->former_name ) };
414 }
415  
416 0 ▶ $old_t ||= eval { $p{old}->table( $new_t->name ) };
Condition0%0/3
$old_t ||= eval { do { $p{"old"}->table($new_t->name) } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$old_t ||= eval { do { $p{"old"}->table($new_t->name) } }
$old_t eval { do { $p{"old"}->table($new_t->name) } }
Truth table0%0/3
A ||= B
A= $old_tB= eval { do { $p{"old"}->table($new_t->name) } }
ABresult
1X1
011
000
417  
418 0 ▶ if ($old_t)
Branch: 1 branch
BranchTrueFalseTotal
if ($old_t) { } 0 0 0
419 {
420 0 ▶ if ( $old_t->name ne $new_t->name )
Branch: 1 branch
BranchTrueFalseTotal
if ($old_t->name ne $new_t->name) 0 0 0
421 {
422 0 $changed_name{ $old_t->name } = 1;
423  
424 0 ▶ if ( $self->can_alter_table_name )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can_alter_table_name) { } 0 0 0
425 {
426 0 push @sql, $self->alter_table_name_sql($new_t);
427 }
428 else
429 {
430 0 push @sql, $self->recreate_table_sql( new => $new_t,
431 old => $old_t,
432 );
433 0 push @sql, $self->rename_sequences( new => $new_t,
434 old => $old_t,
435 );
436  
437 # no need to do more because table will be
438 # recreated from scratch
439 0 next;
440 }
441 }
442  
443 push @sql,
444 0 eval { $self->table_sql_diff( new => $new_t,
445 old => $old_t ) };
446  
447 0 ▶ if ( my $e = Exception::Class->caught('Alzabo::Exception::RDBMSRules::RecreateTable' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (my $e = 'Exception::Class'->caught('Alzabo::Exception::RDBMSRules::RecreateTable')) { } 0 0 0
elsif ($e = $@) { } 0 0 0
448 {
449 0 push @sql, $self->recreate_table_sql( new => $new_t,
450 old => $old_t,
451 );
452 }
453 elsif ( $e = $@ )
454 {
455 0 die $e;
456 }
457 }
458 else
459 {
460 0 push @sql, $self->table_sql($new_t);
461 0 foreach my $fk ( $new_t->all_foreign_keys )
462 {
463 0 push @{ $self->{state}{deferred_sql} }, $self->foreign_key_sql($fk);
464 }
465 }
466 }
467  
468 0 foreach my $old_t ( $p{old}->tables )
469 {
470 0 ▶ unless ( $changed_name{ $old_t->name } ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($changed_name{$old_t->name} or eval { do { $p{"new"}->table($old_t->name) } }) 0 0 0
Condition0%0/3
$changed_name{$old_t->name} or eval { do { $p{"new"}->table($old_t->name) } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$changed_name{$old_t->name} or eval { do { $p{"new"}->table($old_t->name) } }
$changed_name{$old_t->name} eval { do { $p{"new"}->table($old_t->name) } }
Truth table0%0/3
A or B
A= $changed_name{$old_t->name}B= eval { do { $p{"new"}->table($old_t->name) } }
ABresult
1X1
011
000
471 0 eval { $p{new}->table( $old_t->name ) } )
472 {
473 0 push @sql, $self->drop_table_sql($old_t);
474 }
475 }
476  
477 0 ▶ return @sql, @{ $self->{state}{deferred_sql} || [] };
Condition0%0/2
$self->{'state'}{'deferred_sql'} || []
l!l
00
MC/DC0%0/1
$self->{'state'}{'deferred_sql'} || []
$self->{'state'}{'deferred_sql'}
Truth table0%0/2
A
A= $self->{'state'}{'deferred_sql'}
Aresult
11
00
478 }
479  
480 sub table_sql_diff
481 0 ▶{
Subroutine table_sql_diff: not called CC=38 SCAR=73.0
Pod documented
482 0 my $self = shift;
483  
484 0 validate( @_, { new => { isa => 'Alzabo::Table' },
485 old => { isa => 'Alzabo::Table' } } );
486  
487 0 my %p = @_;
488 0 my @sql;
489 0 foreach my $old_i ( $p{old}->indexes )
490 {
491 0 ▶ unless ( eval { $p{new}->index( $old_i->id ) } )
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $p{"new"}->index($old_i->id) } }) 0 0 0
492 {
493 push @sql, $self->drop_index_sql($old_i, $p{new}->name)
494 0 ▶ if eval { $p{new}->columns( map { $_->name } $old_i->columns ) } && ! $@;
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $p{"new"}->columns(map({$_->name;} $old_i->columns)) } } and not $@ 0 0 0
Condition0%0/3
eval { do { $p{"new"}->columns(map({$_->name;} $old_i->columns)) } } and not $@
!ll&&!rl&&r
000
MC/DC0%0/2
eval { do { $p{"new"}->columns(map({$_->name;} $old_i->columns)) } } and not $@
eval { do { $p{"new"}->columns(map({$_->name;} $old_i->columns)) } } not $@
Truth table0%0/3
A and not(B)
A= eval { do { $p{"new"}->columns(map({$_->name;} $old_i->columns)) } }B= not $@
ABresult
0X0
100
111
495 }
496 }
497  
498 0 my %changed_name;
499 0 foreach my $new_c ( $p{new}->columns )
500 {
501 0 ▶ $changed_name{ $new_c->former_name } = 1
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_c->former_name and $new_c->former_name ne $new_c->name 0 0 0
Condition0%0/3
defined $new_c->former_name and $new_c->former_name ne $new_c->name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $new_c->former_name and $new_c->former_name ne $new_c->name
defined $new_c->former_name $new_c->former_name ne $new_c->name
Truth table0%0/3
A and B
A= defined $new_c->former_nameB= $new_c->former_name ne $new_c->name
ABresult
0X0
100
111
502 if defined $new_c->former_name && $new_c->former_name ne $new_c->name;
503 }
504  
505 0 foreach my $old_c ( $p{old}->columns )
506 {
507 0 ▶ unless ( $changed_name{ $old_c->name } ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($changed_name{$old_c->name} or my $new_c = eval { do { $p{"new"}->column($old_c->name) } }) 0 0 0
Condition0%0/3
$changed_name{$old_c->name} or my $new_c = eval { do { $p{"new"}->column($old_c->name) } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$changed_name{$old_c->name} or my $new_c = eval { do { $p{"new"}->column($old_c->name) } }
$changed_name{$old_c->name} my $new_c = eval { do { $p{"new"}->column($old_c->name) } }
Truth table0%0/3
A or B
A= $changed_name{$old_c->name}B= my $new_c = eval { do { $p{"new"}->column($old_c->name) } }
ABresult
1X1
011
000
508 0 ( my $new_c = eval { $p{new}->column( $old_c->name ) } )
509 )
510 {
511 push @sql, $self->drop_column_sql( new_table => $p{new},
512 0 old => $old_c );
513 }
514 }
515  
516 0 foreach my $new_c ( $p{new}->columns )
517 {
518 # When syncing against an existing schema, the column may be
519 # present with its new name.
520 0 my $old_c;
521 0 ▶ if ( defined $new_c->former_name )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_c->former_name) 0 0 0
522 {
523 0 $old_c = eval { $p{old}->column( $new_c->former_name ) };
524 }
525  
526 0 ▶ $old_c ||= eval { $p{old}->column( $new_c->name ) };
Condition0%0/3
$old_c ||= eval { do { $p{"old"}->column($new_c->name) } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$old_c ||= eval { do { $p{"old"}->column($new_c->name) } }
$old_c eval { do { $p{"old"}->column($new_c->name) } }
Truth table0%0/3
A ||= B
A= $old_cB= eval { do { $p{"old"}->column($new_c->name) } }
ABresult
1X1
011
000
527  
528 0 ▶ if ($old_c)
Branch: 1 branch
BranchTrueFalseTotal
if ($old_c) { } 0 0 0
529 {
530 0 ▶ if ( $old_c->name ne $new_c->name )
Branch: 1 branch
BranchTrueFalseTotal
if ($old_c->name ne $new_c->name) 0 0 0
531 {
532 0 ▶ if ( $self->can_alter_column_name )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can_alter_column_name) { } 0 0 0
533 {
534 0 push @sql, $self->alter_column_name_sql($new_c);
535 }
536 else
537 {
538 # no need to do more because table will be
539 # recreated from scratch
540 0 recreate_table_exception();
541 }
542 }
543  
544 0 push @sql, $self->column_sql_diff( new => $new_c,
545 old => $old_c,
546 );
547 }
548 else
549 {
550 0 push @sql, $self->column_sql_add($new_c);
551 }
552 }
553  
554 0 foreach my $new_i ( $p{new}->indexes )
555 {
556 0 ▶ if ( my $old_i = eval { $p{old}->index( $new_i->id ) } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $old_i = eval { do { $p{'old'}->index($new_i->id) } }) { } 0 0 0
557 {
558 0 push @sql, $self->index_sql_diff( new => $new_i,
559 old => $old_i );
560 }
561 else
562 {
563 0 push @sql, $self->index_sql($new_i)
564 }
565 }
566  
567 0 foreach my $new_fk ( $p{new}->all_foreign_keys )
568 {
569 0 ▶ unless ( grep { $new_fk->id eq $_->id } $p{old}->all_foreign_keys )
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$new_fk->id eq $_->id;} $p{"old"}->all_foreign_keys) 0 0 0
570 {
571 0 push @{ $self->{state}{deferred_sql} }, $self->foreign_key_sql($new_fk)
572 }
573 }
574  
575 0 foreach my $old_fk ( $p{old}->all_foreign_keys )
576 {
577 0 ▶ unless ( grep { $old_fk->id eq $_->id } $p{new}->all_foreign_keys )
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$old_fk->id eq $_->id;} $p{"new"}->all_foreign_keys) 0 0 0
578 {
579 0 push @sql, $self->drop_foreign_key_sql($old_fk);
580 }
581 }
582  
583 0 my $pk_changed;
584 0 foreach my $old_pk ( $p{old}->primary_key )
585 {
586 0 ▶ next if $changed_name{ $old_pk->name };
Branch: 1 branch
BranchTrueFalseTotal
if $changed_name{$old_pk->name} 0 0 0
587  
588 0 my $new_col = eval { $p{new}->column( $old_pk->name ) };
589 0 ▶ unless ( $new_col && $new_col->is_primary_key )
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_col and $new_col->is_primary_key) 0 0 0
Condition0%0/3
$new_col and $new_col->is_primary_key
!ll&&!rl&&r
000
MC/DC0%0/2
$new_col and $new_col->is_primary_key
$new_col $new_col->is_primary_key
Truth table0%0/3
A and B
A= $new_colB= $new_col->is_primary_key
ABresult
0X0
100
111
590 {
591 push @sql, $self->alter_primary_key_sql( new => $p{new},
592 0 old => $p{old} );
593  
594 0 $pk_changed = 1;
595 0 last;
596 }
597 }
598  
599 0 ▶ unless ($pk_changed)
Branch: 1 branch
BranchTrueFalseTotal
unless ($pk_changed) 0 0 0
600 {
601 0 foreach my $new_pk ( $p{new}->primary_key )
602 {
603 0 my $old_col = eval { $p{old}->column( $new_pk->name ) };
604  
605 0 ▶ next if $new_pk->former_name && $changed_name{ $new_pk->former_name };
Branch: 1 branch
BranchTrueFalseTotal
if $new_pk->former_name and $changed_name{$new_pk->former_name} 0 0 0
Condition0%0/3
$new_pk->former_name and $changed_name{$new_pk->former_name}
!ll&&!rl&&r
000
MC/DC0%0/2
$new_pk->former_name and $changed_name{$new_pk->former_name}
$new_pk->former_name $changed_name{$new_pk->former_name}
Truth table0%0/3
A and B
A= $new_pk->former_nameB= $changed_name{$new_pk->former_name}
ABresult
0X0
100
111
606  
607 0 ▶ unless ( $old_col && $old_col->is_primary_key )
Branch: 1 branch
BranchTrueFalseTotal
unless ($old_col and $old_col->is_primary_key) 0 0 0
Condition0%0/3
$old_col and $old_col->is_primary_key
!ll&&!rl&&r
000
MC/DC0%0/2
$old_col and $old_col->is_primary_key
$old_col $old_col->is_primary_key
Truth table0%0/3
A and B
A= $old_colB= $old_col->is_primary_key
ABresult
0X0
100
111
608 {
609 push @sql, $self->alter_primary_key_sql( new => $p{new},
610 0 old => $p{old} );
611  
612 0 last;
613 }
614 }
615 }
616  
617 0 my $alter_attributes;
618 0 foreach my $new_att ( $p{new}->attributes )
619 {
620 0 ▶ unless ( $p{old}->has_attribute( attribute => $new_att, case_sensitive => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($p{"old"}->has_attribute("attribute", $new_att, "case_sensitive", 1)) 0 0 0
621 {
622 0 $alter_attributes = 1;
623  
624 push @sql, $self->alter_table_attributes_sql( new => $p{new},
625 old => $p{old},
626 0 );
627  
628 0 last;
629 }
630 }
631  
632 0 ▶ unless ($alter_attributes)
Branch: 1 branch
BranchTrueFalseTotal
unless ($alter_attributes) 0 0 0
633 {
634 0 foreach my $old_att ( $p{old}->attributes )
635 {
636 0 ▶ unless ( $p{new}->has_attribute( attribute => $old_att, case_sensitive => 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($p{"new"}->has_attribute("attribute", $old_att, "case_sensitive", 1)) 0 0 0
637 {
638 0 $alter_attributes = 1;
639  
640 push @sql, $self->alter_table_attributes_sql( new => $p{new},
641 old => $p{old},
642 0 );
643  
644 0 last;
645 }
646 }
647 }
648  
649 0 return @sql;
650 }
651  
652  
653 sub _virtual
654 0 ▶{
Subroutine _virtual: not called CC=1 SCAR=6.9
655 0 my $self = shift;
656  
657 0 my $sub = (caller(1))[3];
658 0 Alzabo::Exception::VirtualMethod->throw( error =>
659 "$sub is a virtual method and must be subclassed in " . ref $self );
660 }
661  
662 __END__
↑ Summary Alzabo/Create/Schema.pm »