Informix/Diff/PrimaryKey.pm

filter: Statementstmt 93.1% 41 / 44 Branchbran 100% 16 / 16 Conditioncond 72.2% 13 / 18 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 84.5% 82 / 97 CC 19 SCAR 20.8
CC
19
Cov
90%
diff
13.0
_pk_columns
4.2
as_sql
4.0
CRAP 8.0
« Informix/Deploy.pm ↑ Summary Informix/Diff/Index.pm »
1 package DBIO::Informix::Diff::PrimaryKey;
2 # ABSTRACT: Diff operations for Informix primary keys
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::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 24 ▶use DBIO::Informix::Util qw(_quote_ident);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 24 __PACKAGE__->mk_diff_accessors(qw(table_name constraint_name columns replaced));
14  
15  
16 136 ▶sub _pk_columns {
Subroutine _pk_columns: called CC=4 SCAR=14.5
17 136 my ($cols) = @_;
18 29 return [ map { $_->{column_name} }
19 2 ▶ sort { ($a->{pk_position} // 0) <=> ($b->{pk_position} // 0) }
Condition50%2/4
$DBIO::Informix::Diff::PrimaryKey::a->{"pk_position"} // 0
l!l
20
$DBIO::Informix::Diff::PrimaryKey::b->{"pk_position"} // 0
l!l
20
MC/DC0%0/1
$DBIO::Informix::Diff::PrimaryKey::a->{"pk_position"} // 0
$DBIO::Informix::Diff::PrimaryKey::a->{"pk_position"}
MC/DC0%0/1
$DBIO::Informix::Diff::PrimaryKey::b->{"pk_position"} // 0
$DBIO::Informix::Diff::PrimaryKey::b->{"pk_position"}
Truth table50%1/2
A
A= $DBIO::Informix::Diff::PrimaryKey::a->{"pk_position"}
Aresult
11
00
Truth table50%1/2
A
A= $DBIO::Informix::Diff::PrimaryKey::b->{"pk_position"}
Aresult
11
00
20 136 ▶ grep { $_->{is_pk} } @{ $cols // [] } ];
Condition50%1/2
$cols // []
l!l
1360
MC/DC0%0/1
$cols // []
$cols
Truth table50%1/2
A
A= $cols
Aresult
11
00
21 }
22  
23  
24 51 ▶sub diff {
Subroutine diff: called CC=13 SCAR=25.7
Pod documented
25 51 my ($class, $source_cols, $target_cols, $source_tables, $target_tables) = @_;
26 51 ▶ $_ //= {} for $source_cols, $target_cols, $source_tables, $target_tables;
Condition50%1/2
$_ //= {}
l!l
2040
MC/DC0%0/1
$_ //= {}
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
27  
28 51 my @ops;
29 51 for my $table (sort keys %$source_tables) {
30 81 ▶ next unless exists $target_tables->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $target_tables->{$table} 9 72 81
31 next if ($source_tables->{$table}{kind} // '') eq 'view'
32 72 ▶ || ($target_tables->{$table}{kind} // '') eq 'view';
Branch: 1 branch
BranchTrueFalseTotal
if ($source_tables->{$table}{"kind"} // "") eq "view" or ($target_tables->{$table}{"kind"} // "") eq "view" 4 68 72
Condition100%7/7
($source_tables->{$table}{"kind"} // "") eq "view" or ($target_tables->{$table}{"kind"} // "") eq "view"
l!l&&r!l&&!r
3168
$source_tables->{$table}{"kind"} // ""
l!l
648
$target_tables->{$table}{"kind"} // ""
l!l
618
MC/DC50%1/2
($source_tables->{$table}{"kind"} // "") eq "view" or ($target_tables->{$table}{"kind"} // "") eq "view"
$source_tables->{$table}{"kind"} $target_tables->{$table}{"kind"}
Truth table66%2/3
A or B
A= $source_tables->{$table}{"kind"}B= $target_tables->{$table}{"kind"}
ABresult
1X1
011
000
33  
34 68 my ($have, $want) = (_pk_columns($source_cols->{$table}), _pk_columns($target_cols->{$table}));
35 68 ▶ next if join("\0", @$have) eq join("\0", @$want);
Branch: 1 branch
BranchTrueFalseTotal
if join("\0", @$have) eq join("\0", @$want) 58 10 68
36  
37 push @ops, $class->new(action => 'drop', table_name => $table,
38 10 ▶ constraint_name => $source_tables->{$table}{primary_key_name}, columns => $have,
Branch: 2 branches
BranchTrueFalseTotal
if @$have 8 2 10
@$want ? : 5 3 8
39 replaced => (@$want ? 1 : 0)) if @$have;
40 10 ▶ push @ops, $class->new(action => 'add', table_name => $table, columns => $want) if @$want;
Branch: 1 branch
BranchTrueFalseTotal
if @$want 7 3 10
41 }
42 51 return @ops;
43 }
44  
45  
46 12 ▶sub as_sql {
Subroutine as_sql: called CC=4 SCAR=13.9
Pod documented
47 12 my ($self) = @_;
48 12 my $tbl = _quote_ident($self->table_name);
49  
50 12 ▶ if ($self->action eq 'drop') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "drop") 6 6 12
51 6 my $name = $self->constraint_name;
52 6 ▶ die sprintf "Informix primary key of table %s cannot be dropped: the model holds no name for it (primary_key_name of the table in the tables section)\n",
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 1 5 6
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
105
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
53 $self->table_name unless defined $name && length $name;
54 5 return sprintf 'ALTER TABLE %s DROP CONSTRAINT %s;', $tbl, _quote_ident($name);
55 }
56  
57 return sprintf 'ALTER TABLE %s ADD CONSTRAINT PRIMARY KEY (%s);', $tbl,
58 6 join(', ', map { _quote_ident($_) } @{ $self->columns });
59 }
60  
61  
62 0 ▶sub summary {
Subroutine summary: not called CC=1 SCAR=6.9
Pod documented
63 0 my ($self) = @_;
64 return sprintf '%s primary key: (%s) on %s', $self->summary_prefix,
65 0 join(', ', @{ $self->columns }), $self->table_name;
66 }
67  
68 24 1;
69  
70 __END__
« Informix/Deploy.pm ↑ Summary Informix/Diff/Index.pm »