Oracle/Diff/Unique.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 87.5% 7 / 8 Conditioncond 61.5% 16 / 26 MC/DCmcdc 33.3% 5 / 15 Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 79.8% 95 / 119 CC 19 SCAR 25.3
CC
19
Cov
86%
diff
18.3
__ANON__
2.0
as_sql
2.0
CRAP 12.5
« Oracle/SQLMaker/Joins.pm ↑ Summary Oracle/Introspect.pm »
1 package DBIO::Oracle::Diff::Unique;
2 # ABSTRACT: Diff operations for the unique constraints of Oracle tables
3  
4 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 our $VERSION = '0.900007';
8  
9 30 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 30 ▶use DBIO::Oracle::Identifier ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 30 __PACKAGE__->mk_diff_accessors(qw(table_name constraint_name columns));
14  
15  
16  
17 118 ▶sub diff {
Subroutine diff: called CC=17 SCAR=29.1
Pod documented
18 118 my ($class, $source, $target, $source_tables, $target_tables, $target_columns) = @_;
19 118 ▶ $source ||= {};
Condition50%1/2
$source ||= {}
l!l
1180
MC/DC0%0/1
$source ||= {}
$source
Truth table50%1/2
A
A= $source
Aresult
11
00
20 118 ▶ $target ||= {};
Condition50%1/2
$target ||= {}
l!l
1180
MC/DC0%0/1
$target ||= {}
$target
Truth table50%1/2
A
A= $target
Aresult
11
00
21 118 ▶ $source_tables ||= $source;
Condition33%1/3
$source_tables ||= $source
l!l&&r!l&&!r
11800
MC/DC0%0/2
$source_tables ||= $source
$source_tables $source
Truth table33%1/3
A ||= B
A= $source_tablesB= $source
ABresult
1X1
011
000
22 118 ▶ $target_tables ||= $target;
Condition33%1/3
$target_tables ||= $target
l!l&&r!l&&!r
11800
MC/DC0%0/2
$target_tables ||= $target
$target_tables $target
Truth table33%1/3
A ||= B
A= $target_tablesB= $target
ABresult
1X1
011
000
23 118 ▶ $target_columns ||= {};
Condition50%1/2
$target_columns ||= {}
l!l
1180
MC/DC0%0/1
$target_columns ||= {}
$target_columns
Truth table50%1/2
A
A= $target_columns
Aresult
11
00
24  
25 118 ▶ my $sig = sub { join "\x1f", @{ $_[0][1] // [] } };
Subroutine __ANON__: called CC=2 SCAR=7.1
Condition50%1/2
$_[0][1] // []
l!l
540
MC/DC0%0/1
$_[0][1] // []
$_[0][1]
Truth table50%1/2
A
A= $_[0][1]
Aresult
11
00
26  
27 118 my @ops;
28 118 my %walk = map { $_ => 1 } keys %$source, keys %$target;
29 118 for my $table (sort keys %walk) {
30 38 ▶ next unless exists $source_tables->{$table} && exists $target_tables->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $source_tables->{$table} and exists $target_tables->{$table} 9 29 38
Condition100%3/3
exists $source_tables->{$table} and exists $target_tables->{$table}
!ll&&!rl&&r
4529
MC/DC100%2/2
exists $source_tables->{$table} and exists $target_tables->{$table}
exists $source_tables->{$table} exists $target_tables->{$table}
Truth table100%3/3
A and B
A= exists $source_tables->{$table}B= exists $target_tables->{$table}
ABresult
0X0
100
111
31 29 ▶ my @src = @{ $source->{$table} // [] };
Condition100%2/2
$source->{$table} // []
l!l
281
MC/DC100%1/1
$source->{$table} // []
$source->{$table}
Truth table100%2/2
A
A= $source->{$table}
Aresult
11
00
32 29 ▶ my @tgt = @{ $target->{$table} // [] };
Condition100%2/2
$target->{$table} // []
l!l
254
MC/DC100%1/1
$target->{$table} // []
$target->{$table}
Truth table100%2/2
A
A= $target->{$table}
Aresult
11
00
33 29 my %have = map { $sig->($_) => 1 } @src;
34 29 my %want = map { $sig->($_) => 1 } @tgt;
35  
36 # a constraint over a column the target drops goes with the column
37 my $kept = $target_columns->{$table}
38 29 ▶ ? { map { lc($_->{column_name}) => 1 } @{ $target_columns->{$table} } } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$target_columns->{$table} ? : 29 0 29
39  
40 29 for my $uc (grep { !$want{ $sig->($_) } } @src) {
41 9 ▶ next if $kept && grep { !$kept->{ lc $_ } } @{ $uc->[1] // [] };
Branch: 1 branch
BranchTrueFalseTotal
if $kept and grep {not $$kept{lc $_};} @{$uc->[1] // [];} 1 8 9
Condition60%3/5
$kept and grep {not $$kept{lc $_};} @{$uc->[1] // [];}
!ll&&!rl&&r
081
$uc->[1] // []
l!l
90
MC/DC50%1/2
$kept and grep {not $$kept{lc $_};} @{$uc->[1] // [];}
$kept grep {not $$kept{lc $_};} @{$uc->[1] // [];}
MC/DC0%0/1
$uc->[1] // []
$uc->[1]
Truth table66%2/3
A and B
A= $keptB= grep {not $$kept{lc $_};} @{$uc->[1] // [];}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $uc->[1]
Aresult
11
00
42 8 push @ops, $class->new(
43 action => 'drop', table_name => $table,
44 constraint_name => $uc->[0], columns => $uc->[1],
45 );
46 }
47 29 for my $uc (grep { !$have{ $sig->($_) } } @tgt) {
48 6 push @ops, $class->new(
49 action => 'create', table_name => $table,
50 constraint_name => $uc->[0], columns => $uc->[1],
51 );
52 }
53 }
54 118 return @ops;
55 }
56  
57  
58 11 ▶sub as_sql {
Subroutine as_sql: called CC=2 SCAR=6.9
Pod documented
59 11 my ($self) = @_;
60 11 my $q = \&DBIO::Oracle::Identifier::quote;
61 11 my $tbl = DBIO::Oracle::Identifier::quote_table($self->table_name);
62  
63 11 ▶ return sprintf 'ALTER TABLE %s DROP CONSTRAINT %s;', $tbl, $q->($self->constraint_name)
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "drop" 6 5 11
64 if $self->action eq 'drop';
65  
66 return sprintf 'ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s);',
67 5 $tbl, $q->($self->constraint_name), join(', ', map { $q->($_) } @{ $self->columns });
68 }
69  
70  
71 0 ▶sub summary {
Subroutine summary: not called CC=1 SCAR=6.9
Pod documented
72 0 my ($self) = @_;
73 0 return sprintf ' %sunique constraint: %s on %s',
74 $self->summary_prefix, $self->constraint_name, $self->table_name;
75 }
76  
77 30 1;
78  
79 __END__
« Oracle/SQLMaker/Joins.pm ↑ Summary Oracle/Introspect.pm »