Informix/Diff.pm

filter: Statementstmt 100% 67 / 67 Branchbran 100% 2 / 2 Conditioncond 88.2% 15 / 17 MC/DCmcdc 77.7% 7 / 9 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 96.3% 104 / 108 CC 8 SCAR 8.3
CC
8
Cov
98%
_build_operations
5.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.3
« Informix/Introspect/Util.pm ↑ Summary Informix/Util.pm »
1 package DBIO::Informix::Diff;
2 # ABSTRACT: Compare two introspected Informix models
3  
4 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 24 our $VERSION = '0.900007';
8  
9 24 ▶use base 'DBIO::Diff::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 24 ▶use DBIO::Informix::Diff::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 24 ▶use DBIO::Informix::Diff::Column;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 24 ▶use DBIO::Informix::Diff::Index;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 24 ▶use DBIO::Informix::Diff::ForeignKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 24 ▶use DBIO::Informix::Diff::UniqueConstraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 24 ▶use DBIO::Informix::Diff::PrimaryKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 49 ▶sub _build_operations {
Subroutine _build_operations: called CC=5 SCAR=16.1
20 49 my ($self) = @_;
21  
22 my @tables = DBIO::Informix::Diff::Table->diff(
23 $self->source->{tables}, $self->target->{tables},
24 $self->target->{columns},
25 49 );
26 my @columns = DBIO::Informix::Diff::Column->diff(
27 $self->source->{columns}, $self->target->{columns},
28 $self->source->{tables}, $self->target->{tables},
29 49 );
30 my @indexes = DBIO::Informix::Diff::Index->diff(
31 $self->source->{indexes}, $self->target->{indexes},
32 49 );
33 my @uniques = DBIO::Informix::Diff::UniqueConstraint->diff(
34 $self->source->{unique_constraints}, $self->target->{unique_constraints},
35 $self->source->{tables}, $self->target->{tables},
36 49 );
37 my @pks = DBIO::Informix::Diff::PrimaryKey->diff(
38 $self->source->{columns}, $self->target->{columns},
39 $self->source->{tables}, $self->target->{tables},
40 49 );
41 # a key that stays over a primary key or constraint dropped here is dropped
42 # before it and added again (karr k27, k28)
43 my @fks = DBIO::Informix::Diff::ForeignKey->diff(
44 $self->source->{foreign_keys}, $self->target->{foreign_keys},
45 $self->source->{tables}, $self->target->{tables},
46 49 DBIO::Informix::Diff::UniqueConstraint->dropped_keys(@uniques, @pks),
47 );
48  
49 # A view is dropped before anything it may read from is changed and
50 # created after everything it reads from exists.
51 49 ▶ my @view_drops = grep { $_->isa('DBIO::Informix::Diff::Table') && $_->is_view && $_->action eq 'drop' } @tables;
Condition83%5/6
$_->isa('DBIO::Informix::Diff::Table') && $_->is_view && $_->action eq 'drop'
!ll&&!rl&&r
1685
$_->isa("DBIO::Informix::Diff::Table") and $_->is_view
!ll&&!rl&&r
01613
MC/DC66%2/3
$_->isa('DBIO::Informix::Diff::Table') && $_->is_view && $_->action eq 'drop'
$_->isa("DBIO::Informix::Diff::Table") $_->is_view $_->action eq 'drop'
Truth table75%3/4
A and B && C
A= $_->isa("DBIO::Informix::Diff::Table")B= $_->is_viewC= $_->action eq 'drop'
ABCresult
0XX0
10X0
1100
1111
52 49 ▶ my @view_creates = grep { $_->isa('DBIO::Informix::Diff::Table') && $_->is_view && $_->action ne 'drop' } @tables;
Condition83%5/6
$_->isa('DBIO::Informix::Diff::Table') && $_->is_view && $_->action ne 'drop'
!ll&&!rl&&r
1658
$_->isa("DBIO::Informix::Diff::Table") and $_->is_view
!ll&&!rl&&r
01613
MC/DC66%2/3
$_->isa('DBIO::Informix::Diff::Table') && $_->is_view && $_->action ne 'drop'
$_->isa("DBIO::Informix::Diff::Table") $_->is_view $_->action ne 'drop'
Truth table75%3/4
A and B && C
A= $_->isa("DBIO::Informix::Diff::Table")B= $_->is_viewC= $_->action ne 'drop'
ABCresult
0XX0
10X0
1100
1111
53 49 @tables = grep { !$_->is_view } @tables;
54  
55 # A view that reads another is dropped before and created after it, where
56 # its definition names the other, whatever the alphabet says.
57 49 ▶ my $def_of = sub { my ($op) = @_; $op->table_info->{definition} // '' };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$op->table_info->{"definition"} // ""
l!l
121
MC/DC100%1/1
$op->table_info->{"definition"} // ""
$op->table_info->{"definition"}
Truth table100%2/2
A
A= $op->table_info->{"definition"}
Aresult
11
00
58 98 ▶ my $order = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
59 98 my ($ops, $reverse) = @_;
60 98 my %op = map { $_->table_name => $_ } @$ops;
61 13 ▶ my @names = DBIO::Diff::Op::_order_by_dependency(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
62 13 my $src = $def_of->($op{ $_[0] });
63 13 ▶ [ grep { $_ ne $_[0] && $src =~ /(?<![\w\$])\Q$_\E(?![\w\$])/i } keys %op ];
Condition100%3/3
$_ ne $_[0] && $src =~ /(?<![\w\$])\Q$_\E(?![\w\$])/i
!ll&&!rl&&r
13113
MC/DC100%2/2
$_ ne $_[0] && $src =~ /(?<![\w\$])\Q$_\E(?![\w\$])/i
$_ ne $_[0] $src =~ /(?<![\w\$])\Q$_\E(?![\w\$])/i
Truth table100%3/3
A && B
A= $_ ne $_[0]B= $src =~ /(?<![\w\$])\Q$_\E(?![\w\$])/i
ABresult
0X0
100
111
64 98 }, keys %op);
65 98 ▶ @names = reverse @names if $reverse;
Branch: 1 branch
BranchTrueFalseTotal
if $reverse 49 49 98
66 98 return map { $op{$_} } @names;
67 49 };
68 49 @view_drops = $order->(\@view_drops, 1);
69 49 @view_creates = $order->(\@view_creates, 0);
70  
71 # Dropping a column drops the constraints and indexes on it, dropping a
72 # table drops its indexes: a DROP CONSTRAINT / DROP INDEX behind either
73 # fails (-623 / -319, measured on Informix 15.0.1, karr k20). So the drops
74 # of foreign keys and indexes lead, their creation trails.
75 return [
76 @view_drops,
77 25 (grep { $_->action eq 'drop' } @fks),
78 12 (grep { $_->action eq 'drop' } @pks),
79 19 (grep { $_->action eq 'drop' } @uniques),
80 4 (grep { $_->action eq 'drop' } @indexes),
81 @tables,
82 @columns,
83 12 (grep { $_->action ne 'drop' } @pks),
84 19 (grep { $_->action ne 'drop' } @uniques),
85 4 (grep { $_->action ne 'drop' } @indexes),
86 49 (grep { $_->action ne 'drop' } @fks),
87 @view_creates,
88 ];
89 }
90  
91 24 1;
92  
93 __END__
« Informix/Introspect/Util.pm ↑ Summary Informix/Util.pm »