Oracle/Diff/Index.pm

filter: Statementstmt 100% 53 / 53 Branchbran 87.5% 7 / 8 Conditioncond 60.0% 9 / 15 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 85.0% 85 / 100 CC 12 SCAR 14.7
CC
12
Cov
91%
diff
8.2
as_sql
5.0
BEGIN
1.0
CRAP 4.4
« Oracle/Identifier.pm ↑ Summary Oracle/Storage/ConnectSetup.pm »
1 package DBIO::Oracle::Diff::Index;
2 # ABSTRACT: Diff operations for Oracle indexes
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 30 ▶use DBIO::Diff::Compare qw(changed_index_fields);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 30 __PACKAGE__->mk_diff_accessors(qw(index_name table_name index_info));
15  
16  
17  
18 46 ▶sub diff {
Subroutine diff: called CC=8 SCAR=21.0
Pod documented
19 46 my ($class, $source, $target, $source_tables, $target_tables) = @_;
20 46 ▶ $source ||= {};
Condition50%1/2
$source ||= {}
l!l
460
MC/DC0%0/1
$source ||= {}
$source
Truth table50%1/2
A
A= $source
Aresult
11
00
21 46 ▶ $target ||= {};
Condition50%1/2
$target ||= {}
l!l
460
MC/DC0%0/1
$target ||= {}
$target
Truth table50%1/2
A
A= $target
Aresult
11
00
22 46 ▶ $source_tables ||= $source;
Condition66%2/3
$source_tables ||= $source
l!l&&r!l&&!r
4060
MC/DC0%0/2
$source_tables ||= $source
$source_tables $source
Truth table66%2/3
A ||= B
A= $source_tablesB= $source
ABresult
1X1
011
000
23 46 ▶ $target_tables ||= $target;
Condition66%2/3
$target_tables ||= $target
l!l&&r!l&&!r
4060
MC/DC0%0/2
$target_tables ||= $target
$target_tables $target
Truth table66%2/3
A ||= B
A= $target_tablesB= $target
ABresult
1X1
011
000
24  
25 9 ▶ my $new_index = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
26 9 my ($tbl, $idx_name, $idx) = @_;
27 9 return $class->new(
28 action => 'create',
29 index_name => $idx_name,
30 table_name => $tbl,
31 index_info => $idx,
32 );
33 46 };
34  
35 my @ops = $class->diff_nested(
36 $source, $target,
37 scope => 'both',
38 source_tables => $source_tables,
39 target_tables => $target_tables,
40 10 ▶ changed_when => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
41 10 my ($old, $new) = @_;
42 10 return scalar changed_index_fields($old, $new);
43 },
44 on_new => $new_index,
45 2 ▶ on_changed => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
46 2 my ($tbl, $idx_name, $old, $new) = @_;
47 return (
48 2 $class->new(
49 action => 'drop',
50 index_name => $idx_name,
51 table_name => $tbl,
52 index_info => $old,
53 ),
54 $class->new(
55 action => 'create',
56 index_name => $idx_name,
57 table_name => $tbl,
58 index_info => $new,
59 ),
60 );
61 },
62 6 ▶ on_gone => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
63 6 my ($tbl, $idx_name, $idx) = @_;
64 6 $class->new(
65 action => 'drop',
66 index_name => $idx_name,
67 table_name => $tbl,
68 index_info => $idx,
69 );
70 },
71 46 );
72  
73 # The tables only the target has: all of their indexes are new.
74 46 for my $tbl (sort keys %$target) {
75 34 ▶ next if exists $source_tables->{$tbl} || !exists $target_tables->{$tbl};
Branch: 1 branch
BranchTrueFalseTotal
if exists $source_tables->{$tbl} or not exists $target_tables->{$tbl} 26 8 34
Condition66%2/3
exists $source_tables->{$tbl} or not exists $target_tables->{$tbl}
l!l&&r!l&&!r
2608
MC/DC50%1/2
exists $source_tables->{$tbl} or not exists $target_tables->{$tbl}
exists $source_tables->{$tbl} not exists $target_tables->{$tbl}
Truth table66%2/3
A or not(B)
A= exists $source_tables->{$tbl}B= not exists $target_tables->{$tbl}
ABresult
1X1
011
000
76 8 my $indexes = $target->{$tbl};
77 8 push @ops, map { $new_index->($tbl, $_, $indexes->{$_}) } sort keys %$indexes;
78 }
79  
80 46 return @ops;
81 }
82  
83  
84 23 ▶sub as_sql {
Subroutine as_sql: called CC=5 SCAR=16.1
Pod documented
85 23 my ($self) = @_;
86  
87 23 my $idx = DBIO::Oracle::Identifier::quote_in($self->table_name, $self->index_name);
88 23 my $tbl = DBIO::Oracle::Identifier::quote_table($self->table_name);
89 23 my $info = $self->index_info;
90 23 ▶ my $cols = join(', ', map { DBIO::Oracle::Identifier::quote($_) } @{ $info->{columns} // [] });
Condition50%1/2
$info->{"columns"} // []
l!l
230
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table50%1/2
A
A= $info->{"columns"}
Aresult
11
00
91  
92 23 ▶ if ($self->action eq 'create') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "create") 18 5 23
93 18 ▶ my $unique = $info->{is_unique} ? 'UNIQUE ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$info->{'is_unique'} ? : 5 13 18
94 18 return sprintf 'CREATE %sINDEX %s ON %s (%s);',
95 $unique, $idx, $tbl, $cols;
96 }
97  
98 5 ▶ if ($self->action eq 'drop') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "drop") 5 0 5
99 5 return sprintf 'DROP INDEX %s;', $idx;
100 }
101 }
102  
103  
104 6 ▶sub summary {
Subroutine summary: called CC=1 SCAR=0.0
Pod documented
105 6 my ($self) = @_;
106 6 return sprintf ' %sindex: %s on %s',
107 $self->summary_prefix, $self->index_name, $self->table_name;
108 }
109  
110 30 1;
111  
112 __END__
« Oracle/Identifier.pm ↑ Summary Oracle/Storage/ConnectSetup.pm »