blib/lib/DBIO/PostgreSQL/Diff/Index.pm

filter: Statementstmt 98.9% 457 / 462 Branchbran 88.8% 231 / 260 Conditioncond 64.6% 196 / 303 MC/DCmcdc 35.4% 56 / 158 Subroutinesub 100% 48 / 48 Podpod 100% 3 / 3 totaltotal 80.3% 991 / 1234 CC 274 SCAR 29.9
CC
274
Cov
86%
_new_keys_bind
47.7
diff
45.7
as_sql
34.3
CRAP 19.8
« blib/lib/DBIO/PostgreSQL/Diff/Function.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/OutsideReaders.pm »
1 package DBIO::PostgreSQL::Diff::Index;
2 # ABSTRACT: Diff operations for PostgreSQL indexes
3  
4 107 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 107 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 107 our $VERSION = '0.900007';
8  
9 107 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 107 ▶use DBIO::PostgreSQL::Diff::CaseOnly ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 107 ▶use DBIO::PostgreSQL::Diff::NoStatement ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 107 ▶use DBIO::PostgreSQL::Introspect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 107 ▶use DBIO::PostgreSQL::Util qw(quote_ident quote_qualified deferrable_clause);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 107 ▶use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 107 __PACKAGE__->mk_diff_accessors(qw(
18 table_key schema_name table_name index_name index_info replaced via renamed_from partitions
19 ));
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32 # Every index of one model section, as { schema => { index name => entry } }.
33 252 ▶sub _by_schema {
Subroutine _by_schema: called CC=4 SCAR=13.9
34 252 my ($section, $tables) = @_;
35 252 my %by_schema;
36 252 for my $table_key (keys %$section) {
37 213 for my $idx_name (keys %{ $section->{$table_key} }) {
38 225 my $info = $section->{$table_key}{$idx_name};
39 my ($table_name, $schema_name) = reverse DBIO::PostgreSQL::Introspect->key_names(
40 225 $table_key, table_name => $info, $tables->{$table_key},
41 );
42 225 ▶ $by_schema{ $schema_name // '' }{$idx_name} = {
Condition50%1/2
$schema_name // ""
l!l
2250
MC/DC0%0/1
$schema_name // ""
$schema_name
Truth table50%1/2
A
A= $schema_name
Aresult
11
00
43 table_key => $table_key,
44 schema_name => $schema_name,
45 table_name => $table_name,
46 index_name => $idx_name,
47 index_info => $info,
48 };
49 }
50 }
51 252 return \%by_schema;
52 }
53  
54 # The entries of _by_schema in the order the operations come out: by index
55 # name, then by schema.
56 360 ▶sub _in_order {
Subroutine _in_order: called CC=4 SCAR=14.6
57 360 my ($by_schema) = @_;
58 return
59 34 ▶ sort { $a->{index_name} cmp $b->{index_name} or ($a->{schema_name} // '') cmp ($b->{schema_name} // '') }
Condition57%4/7
$DBIO::PostgreSQL::Diff::Index::a->{'index_name'} cmp $DBIO::PostgreSQL::Diff::Index::b->{'index_name'} || ($DBIO::PostgreSQL::Diff::Index::a->{'schema_name'} // '') cmp ($DBIO::PostgreSQL::Diff::Index::b->{'schema_name'} // '')
l!l&&r!l&&!r
2860
$DBIO::PostgreSQL::Diff::Index::a->{"schema_name"} // ""
l!l
60
$DBIO::PostgreSQL::Diff::Index::b->{"schema_name"} // ""
l!l
60
MC/DC0%0/2
$DBIO::PostgreSQL::Diff::Index::a->{'index_name'} cmp $DBIO::PostgreSQL::Diff::Index::b->{'index_name'} || ($DBIO::PostgreSQL::Diff::Index::a->{'schema_name'} // '') cmp ($DBIO::PostgreSQL::Diff::Index::b->{'schema_name'} // '')
$DBIO::PostgreSQL::Diff::Index::a->{'index_name'} cmp $DBIO::PostgreSQL::Diff::Index::b->{'index_name'} $DBIO::PostgreSQL::Diff::Index::a->{"schema_name"}
MC/DC0%0/1
$DBIO::PostgreSQL::Diff::Index::b->{"schema_name"} // ""
$DBIO::PostgreSQL::Diff::Index::b->{"schema_name"}
Truth table66%2/3
A || B
A= $DBIO::PostgreSQL::Diff::Index::a->{'index_name'} cmp $DBIO::PostgreSQL::Diff::Index::b->{'index_name'}B= $DBIO::PostgreSQL::Diff::Index::a->{"schema_name"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $DBIO::PostgreSQL::Diff::Index::b->{"schema_name"}
Aresult
11
00
60 360 map { values %$_ } values %$by_schema;
61 }
62  
63 # The entries of _by_schema as DBIO::PostgreSQL::Diff::CaseOnly compares them:
64 # a name among the indexes of its table.
65 252 ▶sub _named {
Subroutine _named: called CC=2 SCAR=7.0
66 252 my ($by_schema) = @_;
67 return [
68 225 ▶ map { { %$_, in => [ $_->{schema_name} // '', $_->{table_key} ], name => $_->{index_name} } }
Condition50%1/2
$_->{"schema_name"} // ""
l!l
2250
MC/DC0%0/1
$_->{"schema_name"} // ""
$_->{"schema_name"}
Truth table50%1/2
A
A= $_->{"schema_name"}
Aresult
11
00
69 252 map { values %$_ } values %$by_schema
70 ];
71 }
72  
73 107 my %CONSTRAINT_KIND = (p => 'PRIMARY KEY', u => 'UNIQUE', x => 'EXCLUDE');
74  
75 # The constraint an index stands behind, as the model says it: ($name, $type)
76 # with the type p, u or x, or an empty list for an index without one. A
77 # primary key's index is the constraint's, under the same name, whether or not
78 # the entry has the keys (a model built by hand may not).
79 732 ▶sub _constraint {
Subroutine _constraint: called CC=5 SCAR=16.2
80 732 my ($info, $index_name) = @_;
81 return ($info->{constraint_name}, $info->{constraint_type})
82 732 ▶ if defined $info->{constraint_name} && defined $info->{constraint_type};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"constraint_name"} and defined $info->{"constraint_type"} 475 257 732
Condition66%2/3
defined $info->{"constraint_name"} and defined $info->{"constraint_type"}
!ll&&!rl&&r
2570475
MC/DC50%1/2
defined $info->{"constraint_name"} and defined $info->{"constraint_type"}
defined $info->{"constraint_name"} defined $info->{"constraint_type"}
Truth table66%2/3
A and B
A= defined $info->{"constraint_name"}B= defined $info->{"constraint_type"}
ABresult
0X0
100
111
83 257 ▶ return ($index_name, 'p') if $info->{is_primary} && defined $index_name;
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"is_primary"} and defined $index_name 3 254 257
Condition66%2/3
$info->{"is_primary"} and defined $index_name
!ll&&!rl&&r
25403
MC/DC50%1/2
$info->{"is_primary"} and defined $index_name
$info->{"is_primary"} defined $index_name
Truth table66%2/3
A and B
A= $info->{"is_primary"}B= defined $index_name
ABresult
0X0
100
111
84 254 return;
85 }
86  
87 # An index to create beside one to drop, on the same table, that is the same
88 # name but for its case -- where the one to drop stands behind a constraint:
89 # the drop takes the constraint, and the diff creates no constraint to put in
90 # its place.
91 126 ▶sub _refuse_case_only {
Subroutine _refuse_case_only: called CC=1 SCAR=0.0
92 126 my ($src_indexes, $tgt_indexes) = @_;
93 DBIO::PostgreSQL::Diff::CaseOnly->refuse(
94 "The index to drop is the index of a constraint. PostgreSQL does not drop it by DROP\n"
95 . "INDEX, and dropping the constraint builds the index again under the new name,\n"
96 . 'where a rename keeps it.',
97 map {
98 2 my ($old, $new) = @$_;
99 2 my @schema = grep { defined } $old->{schema_name};
100 {
101 kind => 'index',
102 database => join('.', @schema, $old->{name}),
103 target => join('.', @schema, $new->{name}),
104 rename => sprintf('ALTER INDEX %s RENAME TO %s;',
105 2 quote_qualified(@schema, $old->{name}), quote_ident($new->{name})),
106 }
107 }
108 126 grep { my @constraint = _constraint(@{$_->[0]}{qw( index_info index_name )}); scalar @constraint }
109 DBIO::PostgreSQL::Diff::CaseOnly->pairs(_named($src_indexes), _named($tgt_indexes)),
110 );
111 }
112  
113 # The definition of an index without its name: the text pg_get_indexdef
114 # writes, the name behind INDEX replaced. Two indexes with this text in common
115 # are the same index under two names.
116 126 ▶sub _definition_without_name {
Subroutine _definition_without_name: called CC=2 SCAR=7.0
117 126 my ($definition) = @_;
118 126 ▶ $definition //= '';
Condition50%1/2
$definition //= ""
l!l
1260
MC/DC0%0/1
$definition //= ""
$definition
Truth table50%1/2
A
A= $definition
Aresult
11
00
119 126 $definition =~ s/\A(\s*CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:CONCURRENTLY\s+)?)(?:"(?:[^"]|"")*"|\S+)(\s+ON\s)/$1\0$2/i;
120 126 return $definition;
121 }
122  
123 # The index as a reader calls it, in a message: its name and its table.
124 47 ▶sub _name {
Subroutine _name: called CC=3 SCAR=12.0
125 47 my ($index) = @_;
126 47 ▶ return sprintf '%s on %s', $index->{index_name} // '', $index->{table_key} // '';
Condition50%2/4
$index->{"index_name"} // ""
l!l
470
$index->{"table_key"} // ""
l!l
470
MC/DC0%0/1
$index->{"index_name"} // ""
$index->{"index_name"}
MC/DC0%0/1
$index->{"table_key"} // ""
$index->{"table_key"}
Truth table50%1/2
A
A= $index->{"index_name"}
Aresult
11
00
Truth table50%1/2
A
A= $index->{"table_key"}
Aresult
11
00
127 }
128  
129 # Whether the index is one over NULLS NOT DISTINCT (PostgreSQL 15 and later).
130 # That is in no field of the model: pg_get_indexdef writes it behind the key
131 # list, and a constraint says it as UNIQUE NULLS NOT DISTINCT (cols).
132 29 ▶sub _nulls_not_distinct {
Subroutine _nulls_not_distinct: called CC=3 SCAR=11.1
133 29 my ($info) = @_;
134 29 ▶ return ($info->{definition} // '') =~ /\)\s+NULLS\s+NOT\s+DISTINCT\b/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($info->{'definition'} // '') =~ /\)\s+NULLS\s+NOT\s+DISTINCT\b/ ? : 1 28 29
Condition50%1/2
$info->{"definition"} // ""
l!l
290
MC/DC0%0/1
$info->{"definition"} // ""
$info->{"definition"}
Truth table50%1/2
A
A= $info->{"definition"}
Aresult
11
00
135 }
136  
137 # The timing of a UNIQUE constraint: its DEFERRABLE clause, with the space that
138 # leads it, or nothing. Only a UNIQUE constraint carries it in the model
139 # (karr k147); a primary key's is not read.
140 96 ▶sub _timing {
Subroutine _timing: called CC=3 SCAR=11.0
141 96 my ($info, $type) = @_;
142 96 ▶ return '' unless ($type // '') eq 'u';
Branch: 1 branch
BranchTrueFalseTotal
unless ($type // "") eq "u" 38 58 96
Condition100%2/2
$type // ""
l!l
7620
MC/DC100%1/1
$type // ""
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
143 58 return deferrable_clause($info->{deferrable}, $info->{initially_deferred});
144 }
145  
146 # The constraint clause of the target, as far as the model carries it: what
147 # the diff writes for a constraint it creates, and, where it cannot write it,
148 # what it tells the reader. The elements of an EXCLUDE constraint are not in
149 # the model.
150 38 ▶sub _add_constraint_sql {
Subroutine _add_constraint_sql: called CC=11 SCAR=24.5
151 38 my ($info, $name, $type) = @_;
152 38 ▶ my @columns = @{ $info->{columns} // [] };
Condition50%1/2
$info->{"columns"} // []
l!l
380
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table50%1/2
A
A= $info->{"columns"}
Aresult
11
00
153 return sprintf 'ADD CONSTRAINT %s %s (...)', quote_ident($name), $CONSTRAINT_KIND{$type}
154 38 ▶ if $type eq 'x' || !@columns || grep { !defined } @columns;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "x" or not @columns or grep {not defined $_;} @columns 1 37 38
Condition50%3/6
$type eq "x" or not @columns or grep {not defined $_;} @columns
l!l&&r!l&&!r
0137
$type eq "x" or not @columns
l!l&&r!l&&!r
0038
MC/DC33%1/3
$type eq "x" or not @columns or grep {not defined $_;} @columns
$type eq "x" not @columns grep {not defined $_;} @columns
Truth table50%2/4
A or not(B) or C
A= $type eq "x"B= not @columnsC= grep {not defined $_;} @columns
ABCresult
1XX1
01X1
0011
0000
155 37 ▶ my @include = @{ $info->{include_columns} // [] };
Condition50%1/2
$info->{"include_columns"} // []
l!l
370
MC/DC0%0/1
$info->{"include_columns"} // []
$info->{"include_columns"}
Truth table50%1/2
A
A= $info->{"include_columns"}
Aresult
11
00
156 37 ▶ my %with = %{ $info->{storage_params} // {} };
Condition50%1/2
$info->{"storage_params"} // {}
l!l
370
MC/DC0%0/1
$info->{"storage_params"} // {}
$info->{"storage_params"}
Truth table50%1/2
A
A= $info->{"storage_params"}
Aresult
11
00
157 return sprintf 'ADD CONSTRAINT %s %s%s (%s)%s%s%s',
158 quote_ident($name), $CONSTRAINT_KIND{$type},
159 ($type eq 'u' && _nulls_not_distinct($info) ? ' NULLS NOT DISTINCT' : ''),
160 45 ▶ join(', ', map { quote_ident($_) } @columns),
Branch: 1 branch
BranchTrueFalseTotal
@include ? : 1 36 37
161 1 ▶ (@include ? ' INCLUDE (' . join(', ', map { quote_ident($_) } @include) . ')' : ''),
Branch: 1 branch
BranchTrueFalseTotal
%with ? : 1 36 37
162 37 ▶ (%with ? ' WITH (' . join(', ', map { "$_ = $with{$_}" } sort keys %with) . ')' : ''),
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'u' && _nulls_not_distinct($info) ? : 1 36 37
Condition100%3/3
$type eq "u" and _nulls_not_distinct($info)
!ll&&!rl&&r
8281
MC/DC100%2/2
$type eq "u" and _nulls_not_distinct($info)
$type eq "u" _nulls_not_distinct($info)
Truth table100%3/3
A and B
A= $type eq "u"B= _nulls_not_distinct($info)
ABresult
0X0
100
111
163 _timing($info, $type);
164 }
165  
166 # Whether the source index and the target index differ in what the diff
167 # compares besides the text of the definition: the constraint behind it (kind),
168 # the key columns in the order of the key, the INCLUDE columns, the storage
169 # parameters. The text carries the columns, the INCLUDE list and the
170 # parameters as well; it does not carry the constraint (karr k139). Whether the
171 # index is valid is not compared: the index of a partitioned table is created
172 # from its text, ON ONLY, and is invalid until its partitions have theirs
173 # -- the diff would drop and create it again for ever.
174 33 ▶sub _attributes_differ {
Subroutine _attributes_differ: called CC=8 SCAR=21.0
175 33 my ($src, $tgt) = @_;
176 33 my ($s, $t) = map { $_->{index_info} } $src, $tgt;
177 33 my (undef, $stype) = _constraint($s, $src->{index_name});
178 33 my (undef, $ttype) = _constraint($t, $tgt->{index_name});
179 33 ▶ return 1 if ($stype // '') ne ($ttype // '');
Branch: 1 branch
BranchTrueFalseTotal
if ($stype // "") ne ($ttype // "") 15 18 33
Condition100%4/4
$stype // ""
l!l
1023
$ttype // ""
l!l
2211
MC/DC100%1/1
$stype // ""
$stype
MC/DC100%1/1
$ttype // ""
$ttype
Truth table100%2/2
A
A= $stype
Aresult
11
00
Truth table100%2/2
A
A= $ttype
Aresult
11
00
180 18 ▶ return 1 if _timing($s, $stype) ne _timing($t, $ttype);
Branch: 1 branch
BranchTrueFalseTotal
if _timing($s, $stype) ne _timing($t, $ttype) 3 15 18
181 15 ▶ my $list = sub { join "\0", map { $_ // "\1" } @{ $_[0] // [] } };
Subroutine __ANON__: called CC=3 SCAR=11.0
Condition75%3/4
$_ // "\1"
l!l
240
$_[0] // []
l!l
3822
MC/DC0%0/1
$_ // "\1"
$_
MC/DC100%1/1
$_[0] // []
$_[0]
Truth table50%1/2
A
A= $_
Aresult
11
00
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
182 15 ▶ return 1 if $list->($s->{columns}) ne $list->($t->{columns});
Branch: 1 branch
BranchTrueFalseTotal
if &$list($s->{"columns"}) ne &$list($t->{"columns"}) 0 15 15
183 15 ▶ return 1 if $list->($s->{include_columns}) ne $list->($t->{include_columns});
Branch: 1 branch
BranchTrueFalseTotal
if &$list($s->{"include_columns"}) ne &$list($t->{"include_columns"}) 0 15 15
184 0 ▶ my $params = sub { my $p = $_[0] // {}; join "\0", map { "$_=$p->{$_}" } sort keys %$p };
Subroutine __ANON__: called CC=2 SCAR=7.0
Condition100%2/2
$_[0] // {}
l!l
1416
MC/DC100%1/1
$_[0] // {}
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
185 15 ▶ return 1 if $params->($s->{storage_params}) ne $params->($t->{storage_params});
Branch: 1 branch
BranchTrueFalseTotal
if &$params($s->{"storage_params"}) ne &$params($t->{"storage_params"}) 0 15 15
186 15 return 0;
187 }
188  
189 # The statement a reader runs by hand to put the constraint of $tgt in place of
190 # the index $src, where the diff does not.
191 10 ▶sub _by_hand {
Subroutine _by_hand: called CC=2 SCAR=7.0
192 10 my ($src, $tgt) = @_;
193 10 my ($name, $type) = _constraint($tgt->{index_info}, $tgt->{index_name});
194 10 my @table = grep { defined } @{$tgt}{qw( schema_name table_name )};
195 return (
196 20 ( $src ? sprintf(' DROP INDEX %s;', quote_qualified(grep { defined } @{$src}{qw( schema_name index_name )})) : () ),
197 10 ▶ sprintf(' ALTER TABLE %s %s;', quote_qualified(@table), _add_constraint_sql($tgt->{index_info}, $name, $type)),
Branch: 1 branch
BranchTrueFalseTotal
$src ? : 10 0 10
198 );
199 }
200  
201 # Whether the foreign key $by, which points at a constraint that is to go, is
202 # gone before the constraint is: the target model declares foreign keys, has the
203 # table of the key, and either lacks the key or has it to other columns. The
204 # drops of the keys come ahead of the drops of the indexes (DBIO::PostgreSQL::
205 # Diff, ORDER OF OPERATIONS). A key the source model does not list -- the copy
206 # at a partition, which the introspection leaves out -- is not shown to be gone.
207 13 ▶sub _foreign_key_goes {
Subroutine _foreign_key_goes: called CC=9 SCAR=22.2
208 13 my ($by, $fk) = @_;
209 13 ▶ my ($source_fks, $target_fks, $target_tables) = @{ $fk // [] };
Condition50%1/2
$fk // []
l!l
130
MC/DC0%0/1
$fk // []
$fk
Truth table50%1/2
A
A= $fk
Aresult
11
00
210 13 ▶ return 0 unless $target_fks;
Branch: 1 branch
BranchTrueFalseTotal
unless $target_fks 3 10 13
211 10 my $key = DBIO::PostgreSQL::Introspect->qualified_key(@{$by}{qw( schema_name table_name )});
212 10 ▶ return 0 unless $target_tables && exists $target_tables->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $target_tables and exists $target_tables->{$key} 1 9 10
Condition66%2/3
$target_tables and exists $target_tables->{$key}
!ll&&!rl&&r
019
MC/DC50%1/2
$target_tables and exists $target_tables->{$key}
$target_tables exists $target_tables->{$key}
Truth table66%2/3
A and B
A= $target_tablesB= exists $target_tables->{$key}
ABresult
0X0
100
111
213 9 ▶ my $named = sub { grep { ($_->{constraint_name} // '') eq $by->{constraint_name} } @{ $_[0]{$key} // [] } };
Subroutine __ANON__: called CC=3 SCAR=11.0
Condition75%3/4
$_->{"constraint_name"} // ""
l!l
160
$_[0]{$key} // []
l!l
152
MC/DC0%0/1
$_->{"constraint_name"} // ""
$_->{"constraint_name"}
MC/DC100%1/1
$_[0]{$key} // []
$_[0]{$key}
Truth table50%1/2
A
A= $_->{"constraint_name"}
Aresult
11
00
Truth table100%2/2
A
A= $_[0]{$key}
Aresult
11
00
214 9 ▶ my ($old) = $named->($source_fks // {});
Condition50%1/2
$source_fks // {}
l!l
90
MC/DC0%0/1
$source_fks // {}
$source_fks
Truth table50%1/2
A
A= $source_fks
Aresult
11
00
215 9 ▶ return 0 unless $old;
Branch: 1 branch
BranchTrueFalseTotal
unless $old 1 8 9
216 8 my ($new) = $named->($target_fks);
217 8 ▶ return 1 unless $new;
Branch: 1 branch
BranchTrueFalseTotal
unless $new 3 5 8
218 5 ▶ my $points = sub { join "\0", (map { $_[0]{$_} // '' } qw( remote_schema remote_table )), @{ $_[0]{remote_columns} // [] } };
Subroutine __ANON__: called CC=3 SCAR=11.4
Condition50%2/4
$_[0]{$_} // ""
l!l
200
$_[0]{"remote_columns"} // []
l!l
100
MC/DC0%0/1
$_[0]{$_} // ""
$_[0]{$_}
MC/DC0%0/1
$_[0]{"remote_columns"} // []
$_[0]{"remote_columns"}
Truth table50%1/2
A
A= $_[0]{$_}
Aresult
11
00
Truth table50%1/2
A
A= $_[0]{"remote_columns"}
Aresult
11
00
219 5 ▶ return $points->($old) ne $points->($new) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$points($old) ne &$points($new) ? : 1 4 5
220 }
221  
222 # Why the constraint behind $src cannot go: the lines that say it, with the
223 # statements that settle it. Nothing when it can go -- as ALTER TABLE ... DROP
224 # CONSTRAINT, with the index. A foreign key that points at it is no reason when
225 # it is gone before the constraint is ($fk, see _foreign_key_goes); a constraint
226 # that is dropped and added again ($replaced) goes in the first half of the
227 # operations, ahead of any drop of a key.
228 58 ▶sub _drop_reasons {
Subroutine _drop_reasons: called CC=4 SCAR=13.9
229 58 my ($src, $replaced, $fk) = @_;
230 58 my $info = $src->{index_info};
231 58 ▶ my @by = grep { $replaced || !_foreign_key_goes($_, $fk) } @{ $info->{referenced_by} // [] }
Branch: 1 branch
BranchTrueFalseTotal
my(@by) = grep({$replaced or not _foreign_key_goes($_, $fk);} @{$info->{"referenced_by"} // [];}) or return 12 46 58
Condition100%5/5
$replaced || !_foreign_key_goes($_, $fk)
l!l&&r!l&&!r
394
$info->{"referenced_by"} // []
l!l
4414
MC/DC100%2/2
$replaced || !_foreign_key_goes($_, $fk)
$replaced !_foreign_key_goes($_, $fk)
MC/DC100%1/1
$info->{"referenced_by"} // []
$info->{"referenced_by"}
Truth table100%3/3
A || not(B)
A= $replacedB= !_foreign_key_goes($_, $fk)
ABresult
1X1
011
000
Truth table100%2/2
A
A= $info->{"referenced_by"}
Aresult
11
00
232 or return;
233 return (
234 'foreign keys of other tables point at it, and ALTER TABLE ... DROP CONSTRAINT would fail:',
235 map {
236 12 sprintf ' ALTER TABLE %s DROP CONSTRAINT %s;',
237 12 quote_qualified(@{$_}{qw( schema_name table_name )}), quote_ident($_->{constraint_name})
238 12 } @by,
239 );
240 }
241  
242 # The primary key constraint of the source on the table of $tgt, under another
243 # name than the primary key $tgt is: PostgreSQL takes one per table, and the
244 # diff creates before it drops.
245 57 ▶sub _other_primary {
Subroutine _other_primary: called CC=8 SCAR=21.0
246 57 my ($src_indexes, $tgt) = @_;
247 57 my ($name, $type) = _constraint($tgt->{index_info}, $tgt->{index_name});
248 57 ▶ return unless defined $type && $type eq 'p';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type eq "p" 44 13 57
Condition66%2/3
defined $type and $type eq "p"
!ll&&!rl&&r
04413
MC/DC50%1/2
defined $type and $type eq "p"
defined $type $type eq "p"
Truth table66%2/3
A and B
A= defined $typeB= $type eq "p"
ABresult
0X0
100
111
249 13 for my $other (_in_order($src_indexes)) {
250 12 ▶ next unless $other->{table_key} eq $tgt->{table_key};
Branch: 1 branch
BranchTrueFalseTotal
unless $other->{"table_key"} eq $tgt->{"table_key"} 0 12 12
251 12 ▶ next if $other->{index_name} eq $tgt->{index_name};
Branch: 1 branch
BranchTrueFalseTotal
if $other->{"index_name"} eq $tgt->{"index_name"} 6 6 12
252 6 my (undef, $otype) = _constraint($other->{index_info}, $other->{index_name});
253 6 ▶ return $other if defined $otype && $otype eq 'p';
Branch: 1 branch
BranchTrueFalseTotal
if defined $otype and $otype eq "p" 3 3 6
Condition66%2/3
defined $otype and $otype eq "p"
!ll&&!rl&&r
303
MC/DC50%1/2
defined $otype and $otype eq "p"
defined $otype $otype eq "p"
Truth table66%2/3
A and B
A= defined $otypeB= $otype eq "p"
ABresult
0X0
100
111
254 }
255 10 return;
256 }
257  
258 # Why the constraint of $tgt cannot be created as ALTER TABLE ... ADD
259 # CONSTRAINT (...): the lines that say it. Nothing when it can.
260 38 ▶sub _create_reasons {
Subroutine _create_reasons: called CC=13 SCAR=25.8
261 38 my ($tgt, $src_indexes) = @_;
262 38 my $info = $tgt->{index_info};
263 38 my ($name, $type) = _constraint($info, $tgt->{index_name});
264 38 my @table = grep { defined } @{$tgt}{qw( schema_name table_name )};
265 38 my @reasons;
266  
267 38 ▶ if ($type eq 'x') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "x") 3 35 38
268 return (
269 3 'it is an EXCLUDE constraint, and the model does not carry its elements, so the diff cannot write it:',
270 sprintf(' ALTER TABLE %s ADD CONSTRAINT %s EXCLUDE (...);', quote_qualified(@table), quote_ident($name)),
271 );
272 }
273  
274 35 ▶ my @columns = @{ $info->{columns} // [] };
Condition50%1/2
$info->{"columns"} // []
l!l
350
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table50%1/2
A
A= $info->{"columns"}
Aresult
11
00
275 push @reasons, 'its key has an expression or no column the model names, and a constraint names columns'
276 35 ▶ if !@columns || grep { !defined } @columns;
Branch: 1 branch
BranchTrueFalseTotal
if not @columns or grep {not defined $_;} @columns 1 34 35
Condition66%2/3
not @columns or grep {not defined $_;} @columns
l!l&&r!l&&!r
0134
MC/DC50%1/2
not @columns or grep {not defined $_;} @columns
not @columns grep {not defined $_;} @columns
Truth table66%2/3
not(A) or B
A= not @columnsB= grep {not defined $_;} @columns
ABresult
1X1
011
000
277 1 push @reasons, 'its index has a sort order (' . join(', ', map { "$_ " . $info->{sort_options}{$_} } sort keys %{ $info->{sort_options} })
278 . '), which a constraint cannot have'
279 35 ▶ if %{ $info->{sort_options} // {} };
Branch: 1 branch
BranchTrueFalseTotal
if %{$info->{"sort_options"} // {};} 1 34 35
Condition100%2/2
$info->{"sort_options"} // {}
l!l
341
MC/DC100%1/1
$info->{"sort_options"} // {}
$info->{"sort_options"}
Truth table100%2/2
A
A= $info->{"sort_options"}
Aresult
11
00
280 1 push @reasons, 'its index has an operator class (' . join(', ', map { "$_ " . $info->{opclasses}{$_} } sort keys %{ $info->{opclasses} })
281 . '), which a constraint cannot name'
282 35 ▶ if %{ $info->{opclasses} // {} };
Branch: 1 branch
BranchTrueFalseTotal
if %{$info->{"opclasses"} // {};} 1 34 35
Condition100%2/2
$info->{"opclasses"} // {}
l!l
341
MC/DC100%1/1
$info->{"opclasses"} // {}
$info->{"opclasses"}
Truth table100%2/2
A
A= $info->{"opclasses"}
Aresult
11
00
283 push @reasons, sprintf('its index is a %s index, and a constraint is a btree index', $info->{access_method})
284 35 ▶ if defined $info->{access_method} && $info->{access_method} ne 'btree';
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"access_method"} and $info->{"access_method"} ne "btree" 0 35 35
Condition33%1/3
defined $info->{"access_method"} and $info->{"access_method"} ne "btree"
!ll&&!rl&&r
0350
MC/DC0%0/2
defined $info->{"access_method"} and $info->{"access_method"} ne "btree"
defined $info->{"access_method"} $info->{"access_method"} ne "btree"
Truth table33%1/3
A and B
A= defined $info->{"access_method"}B= $info->{"access_method"} ne "btree"
ABresult
0X0
100
111
285 @reasons = (
286 35 ▶ ( map { "$_," } @reasons ),
Branch: 1 branch
BranchTrueFalseTotal
if @reasons 3 32 35
287 'so the diff cannot write it as a constraint. Declare it as an index of its own, or write the DDL yourself.',
288 ) if @reasons;
289  
290 35 ▶ if (my $other = _other_primary($src_indexes, $tgt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $other = _other_primary($src_indexes, $tgt)) 1 34 35
291 push @reasons,
292 sprintf('the table has the PRIMARY KEY constraint %s in the database, and PostgreSQL takes one per table (multiple primary keys); the diff creates before it drops:', $other->{index_name}),
293 1 sprintf(' ALTER TABLE %s DROP CONSTRAINT %s;', quote_qualified(@table), quote_ident($other->{index_name}));
294 }
295  
296 35 return @reasons;
297 }
298  
299 # Why the index $src cannot become the constraint of $tgt by ALTER TABLE ...
300 # ADD CONSTRAINT ... USING INDEX: the lines that say it. Measured on
301 # PostgreSQL 18.6, the server refuses it for an index that is not unique or not
302 # btree, that has a predicate, an expression, a sort order other than the
303 # default or is not valid, for a partitioned table, and a second primary key;
304 # it renames the index to the name of the constraint. INCLUDE columns and
305 # NULLS NOT DISTINCT are kept. Nothing when it can. An index that is renamed
306 # first ($renamed) has the name of the constraint by the time it is used.
307 22 ▶sub _using_index_reasons {
Subroutine _using_index_reasons: called CC=22 SCAR=31.2
308 22 my ($src, $tgt, $src_tables, $src_indexes, $renamed) = @_;
309 22 my $info = $src->{index_info};
310 22 my ($name, $type) = _constraint($tgt->{index_info}, $tgt->{index_name});
311 22 my @reasons;
312  
313 22 ▶ push @reasons, 'the index is not unique' unless $info->{is_unique} || $info->{is_primary};
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"is_unique"} or $info->{"is_primary"} 2 20 22
Condition66%2/3
$info->{"is_unique"} or $info->{"is_primary"}
l!l&&r!l&&!r
2002
MC/DC50%1/2
$info->{"is_unique"} or $info->{"is_primary"}
$info->{"is_unique"} $info->{"is_primary"}
Truth table66%2/3
A or B
A= $info->{"is_unique"}B= $info->{"is_primary"}
ABresult
1X1
011
000
314 push @reasons, sprintf('the index is a %s index, not btree', $info->{access_method})
315 22 ▶ if defined $info->{access_method} && $info->{access_method} ne 'btree';
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"access_method"} and $info->{"access_method"} ne "btree" 1 21 22
Condition66%2/3
defined $info->{"access_method"} and $info->{"access_method"} ne "btree"
!ll&&!rl&&r
0211
MC/DC50%1/2
defined $info->{"access_method"} and $info->{"access_method"} ne "btree"
defined $info->{"access_method"} $info->{"access_method"} ne "btree"
Truth table66%2/3
A and B
A= defined $info->{"access_method"}B= $info->{"access_method"} ne "btree"
ABresult
0X0
100
111
316 22 ▶ push @reasons, 'the index has a predicate (it is a partial index)' if length($info->{predicate} // '');
Branch: 1 branch
BranchTrueFalseTotal
if length($info->{"predicate"} // "") 1 21 22
Condition100%2/2
$info->{"predicate"} // ""
l!l
121
MC/DC100%1/1
$info->{"predicate"} // ""
$info->{"predicate"}
Truth table100%2/2
A
A= $info->{"predicate"}
Aresult
11
00
317 push @reasons, 'the index has an expression'
318 22 ▶ if length($info->{expressions} // '') || grep { !defined } @{ $info->{columns} // [] };
Branch: 1 branch
BranchTrueFalseTotal
if length($info->{"expressions"} // "") or grep {not defined $_;} @{$info->{"columns"} // [];} 1 21 22
Condition71%5/7
length($info->{"expressions"} // "") or grep {not defined $_;} @{$info->{"columns"} // [];}
l!l&&r!l&&!r
1021
$info->{"expressions"} // ""
l!l
121
$info->{"columns"} // []
l!l
210
MC/DC50%1/2
length($info->{"expressions"} // "") or grep {not defined $_;} @{$info->{"columns"} // [];}
$info->{"expressions"} grep {not defined $_;} @{$info->{"columns"} // [];}
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table66%2/3
A or B
A= $info->{"expressions"}B= grep {not defined $_;} @{$info->{"columns"} // [];}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $info->{"columns"}
Aresult
11
00
319 1 push @reasons, 'the index has a sort order other than ascending with the nulls last (' . join(', ', map { "$_ " . $info->{sort_options}{$_} } sort keys %{ $info->{sort_options} }) . ')'
320 22 ▶ if %{ $info->{sort_options} // {} };
Branch: 1 branch
BranchTrueFalseTotal
if %{$info->{"sort_options"} // {};} 1 21 22
Condition50%1/2
$info->{"sort_options"} // {}
l!l
220
MC/DC0%0/1
$info->{"sort_options"} // {}
$info->{"sort_options"}
Truth table50%1/2
A
A= $info->{"sort_options"}
Aresult
11
00
321 push @reasons, 'the index is not valid (a CREATE INDEX CONCURRENTLY that failed)'
322 22 ▶ if defined $info->{is_valid} && !$info->{is_valid};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"is_valid"} and not $info->{"is_valid"} 2 20 22
Condition66%2/3
defined $info->{"is_valid"} and not $info->{"is_valid"}
!ll&&!rl&&r
0202
MC/DC50%1/2
defined $info->{"is_valid"} and not $info->{"is_valid"}
defined $info->{"is_valid"} not $info->{"is_valid"}
Truth table66%2/3
A and not(B)
A= defined $info->{"is_valid"}B= not $info->{"is_valid"}
ABresult
0X0
100
111
323 push @reasons, 'the table is partitioned, and ADD CONSTRAINT ... USING INDEX is not supported on a partitioned table'
324 22 ▶ if (($src_tables->{ $src->{table_key} } // {})->{kind} // '') eq 'p';
Branch: 1 branch
BranchTrueFalseTotal
if (+($$src_tables{$src->{"table_key"}} // {})->{"kind"} // "") eq "p" 2 20 22
Condition50%2/4
+($$src_tables{$src->{"table_key"}} // {})->{"kind"} // ""
l!l
220
$$src_tables{$src->{"table_key"}} // {}
l!l
220
MC/DC0%0/1
+($$src_tables{$src->{"table_key"}} // {})->{"kind"} // ""
$$src_tables{$src->{"table_key"}}
Truth table50%1/2
A
A= $$src_tables{$src->{"table_key"}}
Aresult
11
00
325 push @reasons, sprintf('the constraint is named %s and the index %s: USING INDEX would rename the index to the name of the constraint', $name, $src->{index_name})
326 22 ▶ if $name ne $src->{index_name} && !$renamed;
Branch: 1 branch
BranchTrueFalseTotal
if $name ne $src->{"index_name"} and not $renamed 1 21 22
Condition100%3/3
$name ne $src->{"index_name"} and not $renamed
!ll&&!rl&&r
1291
MC/DC100%2/2
$name ne $src->{"index_name"} and not $renamed
$name ne $src->{"index_name"} not $renamed
Truth table100%3/3
A and not(B)
A= $name ne $src->{"index_name"}B= not $renamed
ABresult
0X0
100
111
327  
328 22 my @primary;
329 22 ▶ if (my $other = _other_primary($src_indexes, $tgt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $other = _other_primary($src_indexes, $tgt)) 2 20 22
330 @primary = (
331 sprintf('the table has the PRIMARY KEY constraint %s in the database, and PostgreSQL takes one per table (multiple primary keys):', $other->{index_name}),
332 2 sprintf(' ALTER TABLE %s DROP CONSTRAINT %s;', quote_qualified(grep { defined } @{$tgt}{qw( schema_name table_name )}), quote_ident($other->{index_name})),
333 );
334 }
335  
336 return (
337 22 ▶ ( @reasons ? (map({ "$_," } @reasons), 'so the diff does not put the constraint on this index. The index goes and the constraint comes, by hand:', _by_hand($src, $tgt)) : () ),
Branch: 1 branch
BranchTrueFalseTotal
@reasons ? : 10 12 22
338 @primary,
339 );
340 }
341  
342 # The refusal for every index that stands behind a constraint and cannot go,
343 # or be created, the way the diff takes it; returns when there is none. @found
344 # are [ $entry, @reasons ], the entry being the one whose constraint the lines
345 # are about.
346 121 ▶sub _refuse_constraint {
Subroutine _refuse_constraint: called CC=3 SCAR=11.0
347 121 my (@found) = @_;
348 121 ▶ return unless @found;
Branch: 1 branch
BranchTrueFalseTotal
unless @found 91 30 121
349 30 my $first = 1;
350 die join "\n",
351 ( map {
352 30 my ($entry, @reasons) = @$_;
353 30 my ($name, $type) = _constraint($entry->{index_info}, $entry->{index_name});
354 my $head = sprintf 'index %s on %s is the index of the %s constraint %s',
355 30 $entry->{index_name}, $entry->{table_key}, $CONSTRAINT_KIND{$type}, $name;
356 30 ▶ ( ($first-- > 0 ? "refusing to diff: $head" : $head), map { " $_" } @reasons )
Branch: 1 branch
BranchTrueFalseTotal
$first-- > 0 ? : 30 0 30
357 } @found ),
358 '',
359 'The diff takes a constraint away with ALTER TABLE ... DROP CONSTRAINT and brings it',
360 'with ALTER TABLE ... ADD CONSTRAINT [... USING INDEX]; it does not do what is named',
361 'above. No statement',
362 'was generated.',
363 '',
364 'Run the statements named above yourself and diff again.',
365 '';
366 }
367  
368 # The foreign keys the target creates (or redefines) that the server would
369 # bind to the index $src: a key to the table of the index, on exactly its key
370 # columns, where the index is a plain unique one. The server takes the first
371 # unique index over the columns it finds -- the older one, not the one the
372 # target adds -- and this index is dropped at the end of the run. Returns the
373 # lines that say it, with the statement that settles it; nothing when there is
374 # no such key.
375 39 ▶sub _new_keys_bind {
Subroutine _new_keys_bind: called CC=28 SCAR=38.7
376 39 my ($src, $source_fks, $target_fks) = @_;
377 39 my $info = $src->{index_info};
378 39 ▶ return unless $target_fks;
Branch: 1 branch
BranchTrueFalseTotal
unless $target_fks 29 10 39
379 10 ▶ return unless $info->{is_unique} || $info->{is_primary};
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"is_unique"} or $info->{"is_primary"} 0 10 10
Condition33%1/3
$info->{"is_unique"} or $info->{"is_primary"}
l!l&&r!l&&!r
1000
MC/DC0%0/2
$info->{"is_unique"} or $info->{"is_primary"}
$info->{"is_unique"} $info->{"is_primary"}
Truth table33%1/3
A or B
A= $info->{"is_unique"}B= $info->{"is_primary"}
ABresult
1X1
011
000
380 10 ▶ return if length($info->{predicate} // '') || length($info->{expressions} // '');
Branch: 1 branch
BranchTrueFalseTotal
if length($info->{"predicate"} // "") or length($info->{"expressions"} // "") 0 10 10
Condition42%3/7
length($info->{"predicate"} // "") or length($info->{"expressions"} // "")
l!l&&r!l&&!r
0010
$info->{"predicate"} // ""
l!l
010
$info->{"expressions"} // ""
l!l
010
MC/DC0%0/2
length($info->{"predicate"} // "") or length($info->{"expressions"} // "")
$info->{"predicate"} $info->{"expressions"}
Truth table33%1/3
A or B
A= $info->{"predicate"}B= $info->{"expressions"}
ABresult
1X1
011
000
381 10 ▶ my @columns = @{ $info->{columns} // [] };
Condition50%1/2
$info->{"columns"} // []
l!l
100
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table50%1/2
A
A= $info->{"columns"}
Aresult
11
00
382 10 ▶ return if !@columns || grep { !defined } @columns;
Branch: 1 branch
BranchTrueFalseTotal
if not @columns or grep {not defined $_;} @columns 0 10 10
Condition33%1/3
not @columns or grep {not defined $_;} @columns
l!l&&r!l&&!r
0010
MC/DC0%0/2
not @columns or grep {not defined $_;} @columns
not @columns grep {not defined $_;} @columns
Truth table33%1/3
not(A) or B
A= not @columnsB= grep {not defined $_;} @columns
ABresult
1X1
011
000
383 10 ▶ my $list = sub { join "\0", map { $_ // '' } @_ };
Subroutine __ANON__: called CC=2 SCAR=7.1
Condition50%1/2
$_ // ""
l!l
520
MC/DC0%0/1
$_ // ""
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
384 8 ▶ my $shape = sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
385 8 my ($key) = @_;
386 8 ▶ return $list->(@{$key}{qw( remote_schema remote_table )}, @{ $key->{remote_columns} // [] }, '/', @{ $key->{local_columns} // [] });
Condition50%2/4
$key->{"remote_columns"} // []
l!l
80
$key->{"local_columns"} // []
l!l
80
MC/DC0%0/1
$key->{"remote_columns"} // []
$key->{"remote_columns"}
MC/DC0%0/1
$key->{"local_columns"} // []
$key->{"local_columns"}
Truth table50%1/2
A
A= $key->{"remote_columns"}
Aresult
11
00
Truth table50%1/2
A
A= $key->{"local_columns"}
Aresult
11
00
387 10 };
388 10 my @found;
389 10 for my $table_key (sort keys %$target_fks) {
390 7 for my $key (@{ $target_fks->{$table_key} }) {
391 next unless ($key->{remote_table} // '') eq ($src->{table_name} // '')
392 6 ▶ && ($key->{remote_schema} // '') eq ($src->{schema_name} // '');
Branch: 1 branch
BranchTrueFalseTotal
unless ($key->{"remote_table"} // "") eq ($src->{"table_name"} // "") and ($key->{"remote_schema"} // "") eq ($src->{"schema_name"} // "") 0 6 6
Condition45%5/11
($key->{"remote_table"} // "") eq ($src->{"table_name"} // "") and ($key->{"remote_schema"} // "") eq ($src->{"schema_name"} // "")
!ll&&!rl&&r
006
$key->{"remote_table"} // ""
l!l
60
$src->{"table_name"} // ""
l!l
60
$key->{"remote_schema"} // ""
l!l
60
$src->{"schema_name"} // ""
l!l
60
MC/DC0%0/2
($key->{"remote_table"} // "") eq ($src->{"table_name"} // "") and ($key->{"remote_schema"} // "") eq ($src->{"schema_name"} // "")
$key->{"remote_table"} $key->{"remote_schema"}
MC/DC0%0/1
$src->{"table_name"} // ""
$src->{"table_name"}
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table33%1/3
A and B
A= $key->{"remote_table"}B= $key->{"remote_schema"}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $src->{"table_name"}
Aresult
11
00
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
393 6 ▶ next unless $list->(@{ $key->{remote_columns} // [] }) eq $list->(@columns);
Branch: 1 branch
BranchTrueFalseTotal
unless &$list(@{$key->{"remote_columns"} // [];}) eq &$list(@columns) 1 5 6
Condition50%1/2
$key->{"remote_columns"} // []
l!l
60
MC/DC0%0/1
$key->{"remote_columns"} // []
$key->{"remote_columns"}
Truth table50%1/2
A
A= $key->{"remote_columns"}
Aresult
11
00
394 5 ▶ my ($old) = grep { ($_->{constraint_name} // '') eq $key->{constraint_name} }
Condition50%1/2
$_->{"constraint_name"} // ""
l!l
50
MC/DC0%0/1
$_->{"constraint_name"} // ""
$_->{"constraint_name"}
Truth table50%1/2
A
A= $_->{"constraint_name"}
Aresult
11
00
395 5 ▶ @{ ($source_fks // {})->{$table_key} // [] };
Condition75%3/4
+($source_fks // {})->{$table_key} // []
l!l
41
$source_fks // {}
l!l
50
MC/DC0%0/1
+($source_fks // {})->{$table_key} // []
$source_fks
Truth table50%1/2
A
A= $source_fks
Aresult
11
00
396 5 ▶ next if $old && $shape->($old) eq $shape->($key);
Branch: 1 branch
BranchTrueFalseTotal
if $old and &$shape($old) eq &$shape($key) 4 1 5
Condition66%2/3
$old and &$shape($old) eq &$shape($key)
!ll&&!rl&&r
104
MC/DC50%1/2
$old and &$shape($old) eq &$shape($key)
$old &$shape($old) eq &$shape($key)
Truth table66%2/3
A and B
A= $oldB= &$shape($old) eq &$shape($key)
ABresult
0X0
100
111
397 1 push @found, [ $table_key, $key ];
398 }
399 }
400 10 ▶ return unless @found;
Branch: 1 branch
BranchTrueFalseTotal
unless @found 9 1 10
401 1 my ($constraint) = _constraint($info, $src->{index_name});
402 return (
403 'the foreign key the target creates on its columns would be bound by the server to this index, which the same run drops:',
404 1 ▶ ( map { sprintf ' %s on %s', $_->[1]{constraint_name}, $_->[0] } @found ),
Branch: 1 branch
BranchTrueFalseTotal
defined $constraint ? : 0 1 1
405 'Drop the index first (the key is then created against the constraint of the target), and diff again:',
406 ' ' . (defined $constraint
407 0 ? 'ALTER TABLE ' . quote_qualified(grep { defined } @{$src}{qw( schema_name table_name )}) . ' DROP CONSTRAINT ' . quote_ident($constraint)
408 1 : 'DROP INDEX ' . quote_qualified(grep { defined } @{$src}{qw( schema_name index_name )})) . ';',
409 );
410 }
411  
412 # The refusal for every index the run drops that a foreign key stands on, or
413 # would be bound to; returns when there is none. @found are [ $entry,
414 # @reasons ].
415 91 ▶sub _refuse_bound {
Subroutine _refuse_bound: called CC=3 SCAR=11.0
416 91 my (@found) = @_;
417 91 ▶ return unless @found;
Branch: 1 branch
BranchTrueFalseTotal
unless @found 89 2 91
418 2 my $first = 1;
419 die join "\n",
420 ( map {
421 2 my ($entry, @reasons) = @$_;
422 2 my $head = sprintf 'index %s on %s is dropped by this run', $entry->{index_name}, $entry->{table_key};
423 2 ▶ ( ($first-- > 0 ? "refusing to diff: $head" : $head), map { " $_" } @reasons )
Branch: 1 branch
BranchTrueFalseTotal
$first-- > 0 ? : 2 0 2
424 } @found ),
425 '',
426 'The server refuses to drop an index a foreign key stands on. No statement',
427 'was generated.',
428 '',
429 'Run the statements named above yourself and diff again.',
430 '';
431 }
432  
433 # --- the index of a partitioned table (karr k146) ---
434  
435 107 my $IDENT = qr/"(?:[^"]|"")*"|[^\s".]+/;
436  
437 # The text of the index of a partitioned table at one of its partitions: the
438 # name and the table replaced, ON ONLY kept where the partition is partitioned
439 # itself. Nothing when the text is not the form pg_get_indexdef writes.
440 20 ▶sub _partition_definition {
Subroutine _partition_definition: called CC=3 SCAR=11.0
441 20 my ($definition, $name, $schema, $table, $only) = @_;
442 20 ▶ $definition =~ s/\A(\s*CREATE\s+(?:UNIQUE\s+)?INDEX\s+)(?:$IDENT)(\s+ON\s+)ONLY\s+$IDENT(?:\.$IDENT)?(\s+USING\s)/
Branch: 1 branch
BranchTrueFalseTotal
$definition =~ s/\A(\s*CREATE\s+(?:UNIQUE\s+)?INDEX\s+)(?:$IDENT)(\s+ON\s+)ONLY\s+$IDENT(?:\.$IDENT)?(\s+USING\s)/$1 . quote_ident($name) . $2 . ($only ? "ONLY " : "") . quote_qualified(grep({defined $_;} $schema, $table)) . $3;/ex or return 20 0 20
443 20 ▶ $1 . quote_ident($name) . $2 . ($only ? 'ONLY ' : '') . quote_qualified(grep { defined } $schema, $table) . $3/ex
Branch: 1 branch
BranchTrueFalseTotal
$only ? : 6 14 20
444 or return;
445 20 return $definition;
446 }
447  
448 # The name the server gives an index it names itself (ChooseIndexName): the
449 # table, the columns of the key joined by _ ("expr" for an expression), the
450 # label (idx, idx1, ...); at most 63 bytes, the longer of table and columns
451 # losing a character at a time (makeObjectName).
452 25 ▶sub _partition_index_name {
Subroutine _partition_index_name: called CC=6 SCAR=18.3
453 25 my ($table, $columns, $label) = @_;
454 25 ▶ my $cols = join '_', map { defined $_ && length $_ ? $_ : 'expr' } @$columns;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 28 3 31
Condition66%2/3
defined $_ and length $_
!ll&&!rl&&r
3028
MC/DC50%1/2
defined $_ and length $_
defined $_ length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
455 25 ▶ $cols = 'expr' unless length $cols;
Branch: 1 branch
BranchTrueFalseTotal
unless length $cols 0 25 25
456 25 my ($t, $c) = ($table, $cols);
457 25 ▶ while (bytes::length($t) + bytes::length($c) + bytes::length($label) + 2 > 63) {
Branch: 1 branch
BranchTrueFalseTotal
if (&bytes::length($t) + &bytes::length($c) + &bytes::length($label) + 2 > 63) 15 25 40
458 0 ▶ if (length $t > length $c) { chop $t } else { chop $c }
Branch: 1 branch
BranchTrueFalseTotal
if (length $t > length $c) { } 15 0 15
459 }
460 25 return join '_', $t, $c, $label;
461 }
462  
463 # The tree of indexes to put at the partitions of the table $table_key, for the
464 # index whose text is $definition. $taken is { schema => { name => 1 } } and
465 # grows with the names given. Nothing when the text cannot be rewritten.
466 13 ▶sub _partition_tree {
Subroutine _partition_tree: called CC=14 SCAR=27.0
467 13 my ($source_tables, $target_tables, $table_key, $info, $definition, $taken) = @_;
468 13 my @tree;
469 13 for my $key (sort keys %$source_tables) {
470 67 my $t = $source_tables->{$key};
471 67 ▶ next unless defined $t->{partition_of} && $t->{partition_of} eq $table_key && exists $target_tables->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t->{"partition_of"} and $t->{"partition_of"} eq $table_key and exists $target_tables->{$key} 47 20 67
Condition100%6/6
defined $t->{"partition_of"} and $t->{"partition_of"} eq $table_key and exists $target_tables->{$key}
!ll&&!rl&&r
46120
defined $t->{"partition_of"} and $t->{"partition_of"} eq $table_key
!ll&&!rl&&r
262021
MC/DC100%3/3
defined $t->{"partition_of"} and $t->{"partition_of"} eq $table_key and exists $target_tables->{$key}
defined $t->{"partition_of"} $t->{"partition_of"} eq $table_key exists $target_tables->{$key}
Truth table100%4/4
A and B and C
A= defined $t->{"partition_of"}B= $t->{"partition_of"} eq $table_keyC= exists $target_tables->{$key}
ABCresult
0XX0
10X0
1100
1111
472 20 my $schema = $t->{schema_name};
473 20 ▶ my $name = _partition_index_name($t->{table_name}, $info->{columns} // [], 'idx');
Condition50%1/2
$info->{"columns"} // []
l!l
200
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table50%1/2
A
A= $info->{"columns"}
Aresult
11
00
474 20 ▶ for (my $n = 1; $taken->{ $schema // '' }{$name}; $n++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$taken{$schema // ""}{$name}) 1 20 21
Condition50%1/2
$schema // ""
l!l
210
MC/DC0%0/1
$schema // ""
$schema
Truth table50%1/2
A
A= $schema
Aresult
11
00
475 1 ▶ $name = _partition_index_name($t->{table_name}, $info->{columns} // [], "idx$n");
Condition50%1/2
$info->{"columns"} // []
l!l
10
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table50%1/2
A
A= $info->{"columns"}
Aresult
11
00
476 }
477 20 ▶ $taken->{ $schema // '' }{$name} = 1;
Condition50%1/2
$schema // ""
l!l
200
MC/DC0%0/1
$schema // ""
$schema
Truth table50%1/2
A
A= $schema
Aresult
11
00
478 20 ▶ my $partitioned = ($t->{kind} // '') eq 'p';
Condition50%1/2
$t->{"kind"} // ""
l!l
200
MC/DC0%0/1
$t->{"kind"} // ""
$t->{"kind"}
Truth table50%1/2
A
A= $t->{"kind"}
Aresult
11
00
479 20 ▶ my $text = _partition_definition($definition, $name, $schema, $t->{table_name}, $partitioned) // return;
Condition50%1/2
_partition_definition($definition, $name, $schema, $t->{"table_name"}, $partitioned) // (return)
l!l
200
MC/DC0%0/1
_partition_definition($definition, $name, $schema, $t->{"table_name"}, $partitioned) // (return)
_partition_definition($definition, $name, $schema, $t->{"table_name"}, $partitioned)
Truth table50%1/2
A
A= _partition_definition($definition, $name, $schema, $t->{"table_name"}, $partitioned)
Aresult
11
00
480 20 my $below = [];
481 20 ▶ if ($partitioned) {
Branch: 1 branch
BranchTrueFalseTotal
if ($partitioned) 6 14 20
482 6 ▶ $below = _partition_tree($source_tables, $target_tables, $key, $info, $definition, $taken) // return;
Condition50%1/2
_partition_tree($source_tables, $target_tables, $key, $info, $definition, $taken) // (return)
l!l
60
MC/DC0%0/1
_partition_tree($source_tables, $target_tables, $key, $info, $definition, $taken) // (return)
_partition_tree($source_tables, $target_tables, $key, $info, $definition, $taken)
Truth table50%1/2
A
A= _partition_tree($source_tables, $target_tables, $key, $info, $definition, $taken)
Aresult
11
00
483 }
484 push @tree, {
485 schema_name => $schema,
486 table_name => $t->{table_name},
487 20 index_name => $name,
488 definition => $text,
489 partitions => $below,
490 };
491 }
492 13 return \@tree;
493 }
494  
495 # The statements for $tree below the index $parent (a list: schema, name).
496 76 ▶sub _partition_sql {
Subroutine _partition_sql: called CC=2 SCAR=7.0
497 76 my ($parent, $tree) = @_;
498 return map {
499 76 my $child = $_;
500 (
501 "$child->{definition};",
502 _partition_sql([ $child->{schema_name}, $child->{index_name} ], $child->{partitions} // []),
503 sprintf('ALTER INDEX %s ATTACH PARTITION %s;',
504 40 quote_qualified(grep { defined } @$parent),
505 20 ▶ quote_qualified(grep { defined } @{$child}{qw( schema_name index_name )})),
Condition50%1/2
$child->{"partitions"} // []
l!l
200
MC/DC0%0/1
$child->{"partitions"} // []
$child->{"partitions"}
Truth table50%1/2
A
A= $child->{"partitions"}
Aresult
11
00
506 )
507 } @$tree;
508 }
509  
510 3 ▶sub _refuse_without_definition {
Subroutine _refuse_without_definition: called CC=1 SCAR=0.0
511 3 my ($tgt, $in_database) = @_;
512 3 DBIO::PostgreSQL::Diff::NoStatement->refuse_without_definition(
513 kind => 'index',
514 name => _name($tgt),
515 in_database => $in_database,
516 from => 'pg_get_indexdef',
517 null_when_gone => 1,
518 also => "The columns of the index, which the model may still hold, are not the index:\n"
519 . "whether it is unique, its predicate, its access method, the order and the\n"
520 . 'operator class of each column are in the definition.',
521 );
522 }
523  
524 126 ▶sub diff {
Subroutine diff: called CC=44 SCAR=38.2
Pod documented
525 126 my ($class, $source, $target, $source_tables, $target_tables, $source_fks, $target_fks) = @_;
526 126 my @ops;
527  
528 # Tables present in the source model but absent from the target are being
529 # dropped in this same pass. Their indexes go with the table via
530 # DROP TABLE, so a standalone DROP INDEX for one of them
531 # must be suppressed (karr k32).
532 126 ▶ $source_tables //= {};
Condition100%2/2
$source_tables //= {}
l!l
1233
MC/DC100%1/1
$source_tables //= {}
$source_tables
Truth table100%2/2
A
A= $source_tables
Aresult
11
00
533 126 ▶ $target_tables //= {};
Condition100%2/2
$target_tables //= {}
l!l
1233
MC/DC100%1/1
$target_tables //= {}
$target_tables
Truth table100%2/2
A
A= $target_tables
Aresult
11
00
534 13 my %dropped_table = map { $_ => 1 }
535 126 grep { !exists $target_tables->{$_} } keys %$source_tables;
536  
537 126 my $src_indexes = _by_schema($source, $source_tables);
538 126 my $tgt_indexes = _by_schema($target, $target_tables);
539  
540 126 _refuse_case_only($src_indexes, $tgt_indexes);
541  
542 124 my @constrained;
543  
544 # Indexes this run drops that a foreign key stands on or would be bound to.
545 my @bound;
546  
547 # What decides whether a foreign key that points at a constraint to drop is
548 # gone before it (the foreign_keys sections are optional, undef when absent).
549 124 my $fk = [ $source_fks, $target_fks, $target_tables ];
550  
551 # Indexes of the source that are renamed and given a constraint, by schema
552 # and name, so that they are not dropped as well.
553 124 my %renamed;
554  
555 # The index of the source the constraint of $tgt is put on: on the same
556 # table, with the same definition but for the name, no constraint on it, not
557 # an index the target keeps. Each one serves one constraint.
558 40 ▶ my $renamable = sub {
Subroutine __ANON__: called CC=9 SCAR=22.1
559 40 my ($tgt) = @_;
560 40 my $want = _definition_without_name($tgt->{index_info}{definition});
561 40 for my $src (_in_order($src_indexes)) {
562 27 ▶ next if $src->{table_key} ne $tgt->{table_key};
Branch: 1 branch
BranchTrueFalseTotal
if $src->{"table_key"} ne $tgt->{"table_key"} 1 26 27
563 26 ▶ next if $renamed{ $src->{schema_name} // '' }{ $src->{index_name} };
Branch: 1 branch
BranchTrueFalseTotal
if $renamed{$src->{"schema_name"} // ""}{$src->{"index_name"}} 0 26 26
Condition50%1/2
$src->{"schema_name"} // ""
l!l
260
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
564 26 ▶ next if $tgt_indexes->{ $src->{schema_name} // '' }{ $src->{index_name} };
Branch: 1 branch
BranchTrueFalseTotal
if $$tgt_indexes{$src->{"schema_name"} // ""}{$src->{"index_name"}} 9 17 26
Condition50%1/2
$src->{"schema_name"} // ""
l!l
260
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
565 17 ▶ next if _constraint($src->{index_info}, $src->{index_name});
Branch: 1 branch
BranchTrueFalseTotal
if _constraint($src->{"index_info"}, $src->{"index_name"}) 4 13 17
566 13 ▶ next if _definition_without_name($src->{index_info}{definition}) ne $want;
Branch: 1 branch
BranchTrueFalseTotal
if _definition_without_name($src->{"index_info"}{"definition"}) ne $want 4 9 13
567 9 return $src;
568 }
569 31 return;
570 124 };
571  
572 # The constraint of the source that is the constraint of $tgt under another
573 # name: on the same table, of the same kind, with the same definition but for
574 # the name, a name the target does not keep. It is renamed, ALTER TABLE ...
575 # RENAME CONSTRAINT, which renames its index with it: dropping it and adding
576 # the other would fail where a key stands on it.
577 43 ▶ my $renamable_constraint = sub {
Subroutine __ANON__: called CC=13 SCAR=26.4
578 43 my ($tgt) = @_;
579 43 my (undef, $type) = _constraint($tgt->{index_info}, $tgt->{index_name});
580 43 ▶ return unless defined $type && $type ne 'x';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type ne "x" 0 43 43
Condition33%1/3
defined $type and $type ne "x"
!ll&&!rl&&r
0043
MC/DC0%0/2
defined $type and $type ne "x"
defined $type $type ne "x"
Truth table33%1/3
A and B
A= defined $typeB= $type ne "x"
ABresult
0X0
100
111
581 43 my $want = _definition_without_name($tgt->{index_info}{definition});
582 43 for my $src (_in_order($src_indexes)) {
583 32 ▶ next if $src->{table_key} ne $tgt->{table_key};
Branch: 1 branch
BranchTrueFalseTotal
if $src->{"table_key"} ne $tgt->{"table_key"} 1 31 32
584 31 ▶ next if $renamed{ $src->{schema_name} // '' }{ $src->{index_name} };
Branch: 1 branch
BranchTrueFalseTotal
if $renamed{$src->{"schema_name"} // ""}{$src->{"index_name"}} 0 31 31
Condition50%1/2
$src->{"schema_name"} // ""
l!l
310
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
585 31 ▶ next if $tgt_indexes->{ $src->{schema_name} // '' }{ $src->{index_name} };
Branch: 1 branch
BranchTrueFalseTotal
if $$tgt_indexes{$src->{"schema_name"} // ""}{$src->{"index_name"}} 9 22 31
Condition50%1/2
$src->{"schema_name"} // ""
l!l
310
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
586 22 my (undef, $stype) = _constraint($src->{index_info}, $src->{index_name});
587 22 ▶ next unless defined $stype && $stype eq $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stype and $stype eq $type 14 8 22
Condition66%2/3
defined $stype and $stype eq $type
!ll&&!rl&&r
1408
MC/DC50%1/2
defined $stype and $stype eq $type
defined $stype $stype eq $type
Truth table66%2/3
A and B
A= defined $stypeB= $stype eq $type
ABresult
0X0
100
111
588 8 ▶ next if _definition_without_name($src->{index_info}{definition}) ne $want;
Branch: 1 branch
BranchTrueFalseTotal
if _definition_without_name($src->{"index_info"}{"definition"}) ne $want 2 6 8
589 # A rename keeps the timing of the constraint (karr k147); one that
590 # changes it is a drop and a create, see $retimed.
591 6 ▶ next if _timing($src->{index_info}, $stype) ne _timing($tgt->{index_info}, $type);
Branch: 1 branch
BranchTrueFalseTotal
if _timing($src->{"index_info"}, $stype) ne _timing($tgt->{"index_info"}, $type) 3 3 6
592 3 return $src;
593 }
594 40 return;
595 124 };
596  
597 # The constraint of the source that is the constraint of $tgt under another
598 # name but for its timing (deferrable, initially_deferred): the renamed
599 # constraint would keep the old one, so it is dropped and the target's
600 # created (karr k147).
601 45 ▶ my $retimed = sub {
Subroutine __ANON__: called CC=12 SCAR=25.2
602 45 my ($tgt) = @_;
603 45 my (undef, $type) = _constraint($tgt->{index_info}, $tgt->{index_name});
604 45 ▶ return unless defined $type && $type eq 'u';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type eq "u" 26 19 45
Condition100%3/3
defined $type and $type eq "u"
!ll&&!rl&&r
20619
MC/DC100%2/2
defined $type and $type eq "u"
defined $type $type eq "u"
Truth table100%3/3
A and B
A= defined $typeB= $type eq "u"
ABresult
0X0
100
111
605 19 my $want = _definition_without_name($tgt->{index_info}{definition});
606 19 for my $src (_in_order($src_indexes)) {
607 9 ▶ next if $src->{table_key} ne $tgt->{table_key};
Branch: 1 branch
BranchTrueFalseTotal
if $src->{"table_key"} ne $tgt->{"table_key"} 1 8 9
608 8 ▶ next if $renamed{ $src->{schema_name} // '' }{ $src->{index_name} };
Branch: 1 branch
BranchTrueFalseTotal
if $renamed{$src->{"schema_name"} // ""}{$src->{"index_name"}} 0 8 8
Condition50%1/2
$src->{"schema_name"} // ""
l!l
80
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
609 8 ▶ next if $tgt_indexes->{ $src->{schema_name} // '' }{ $src->{index_name} };
Branch: 1 branch
BranchTrueFalseTotal
if $$tgt_indexes{$src->{"schema_name"} // ""}{$src->{"index_name"}} 1 7 8
Condition50%1/2
$src->{"schema_name"} // ""
l!l
80
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
610 7 my (undef, $stype) = _constraint($src->{index_info}, $src->{index_name});
611 7 ▶ next unless defined $stype && $stype eq $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stype and $stype eq $type 4 3 7
Condition66%2/3
defined $stype and $stype eq $type
!ll&&!rl&&r
403
MC/DC50%1/2
defined $stype and $stype eq $type
defined $stype $stype eq $type
Truth table66%2/3
A and B
A= defined $stypeB= $stype eq $type
ABresult
0X0
100
111
612 3 ▶ next if _definition_without_name($src->{index_info}{definition}) ne $want;
Branch: 1 branch
BranchTrueFalseTotal
if _definition_without_name($src->{"index_info"}{"definition"}) ne $want 0 3 3
613 3 return $src;
614 }
615 16 return;
616 124 };
617  
618 # The operations that put the constraint of $tgt on an index of the source
619 # that has another name: the constraint renamed, or the index renamed and
620 # the constraint put on it. Nothing when there is none.
621 73 ▶ my $take_over = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
622 73 my ($tgt) = @_;
623 73 my (undef, $type) = _constraint($tgt->{index_info}, $tgt->{index_name});
624 73 ▶ return unless defined $type && $type ne 'x';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type ne "x" 30 43 73
Condition100%3/3
defined $type and $type ne "x"
!ll&&!rl&&r
27343
MC/DC100%2/2
defined $type and $type ne "x"
defined $type $type ne "x"
Truth table100%3/3
A and B
A= defined $typeB= $type ne "x"
ABresult
0X0
100
111
625 43 ▶ if (my $old = $renamable_constraint->($tgt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = &$renamable_constraint($tgt)) 3 40 43
626 3 ▶ $renamed{ $old->{schema_name} // '' }{ $old->{index_name} } = 1;
Condition50%1/2
$old->{"schema_name"} // ""
l!l
30
MC/DC0%0/1
$old->{"schema_name"} // ""
$old->{"schema_name"}
Truth table50%1/2
A
A= $old->{"schema_name"}
Aresult
11
00
627 3 return $class->new(action => 'rename', %$tgt, renamed_from => $old->{index_name}, via => 'constraint');
628 }
629 40 ▶ if (my $old = $renamable->($tgt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = &$renamable($tgt)) 9 31 40
630 # A second index would leave the foreign keys on this one (karr k139).
631 9 my @reasons = _using_index_reasons($old, $tgt, $source_tables, $src_indexes, 1);
632 9 ▶ push @constrained, [ $tgt, @reasons ] if @reasons;
Branch: 1 branch
BranchTrueFalseTotal
if @reasons 3 6 9
633 9 ▶ $renamed{ $old->{schema_name} // '' }{ $old->{index_name} } = 1;
Condition50%1/2
$old->{"schema_name"} // ""
l!l
90
MC/DC0%0/1
$old->{"schema_name"} // ""
$old->{"schema_name"}
Truth table50%1/2
A
A= $old->{"schema_name"}
Aresult
11
00
634 return (
635 9 $class->new(action => 'rename', %$tgt, renamed_from => $old->{index_name}),
636 $class->new(action => 'create', %$tgt, via => 'using_index'),
637 );
638 }
639 31 return;
640 124 };
641  
642 # Names the schemas hold: the indexes of the source, and what the server
643 # names the copies of an index of a partitioned table at each partition
644 # (the copies are not in the model).
645 124 my %taken;
646 124 for my $entry (map { values %$_ } values %$src_indexes) {
647 112 ▶ $taken{ $entry->{schema_name} // '' }{ $entry->{index_name} } = 1;
Condition50%1/2
$entry->{"schema_name"} // ""
l!l
1120
MC/DC0%0/1
$entry->{"schema_name"} // ""
$entry->{"schema_name"}
Truth table50%1/2
A
A= $entry->{"schema_name"}
Aresult
11
00
648 112 ▶ next unless (($source_tables->{ $entry->{table_key} } // {})->{kind} // '') eq 'p';
Branch: 1 branch
BranchTrueFalseTotal
unless (+($$source_tables{$entry->{"table_key"}} // {})->{"kind"} // "") eq "p" 108 4 112
Condition100%4/4
+($$source_tables{$entry->{"table_key"}} // {})->{"kind"} // ""
l!l
9220
$$source_tables{$entry->{"table_key"}} // {}
l!l
1102
MC/DC100%1/1
+($$source_tables{$entry->{"table_key"}} // {})->{"kind"} // ""
$$source_tables{$entry->{"table_key"}}
Truth table100%2/2
A
A= $$source_tables{$entry->{"table_key"}}
Aresult
11
00
649 4 ▶ for my $key (grep { ($source_tables->{$_}{partition_of} // '') eq $entry->{table_key} } keys %$source_tables) {
Condition100%2/2
$source_tables->{$_}{"partition_of"} // ""
l!l
66
MC/DC100%1/1
$source_tables->{$_}{"partition_of"} // ""
$source_tables->{$_}{"partition_of"}
Truth table100%2/2
A
A= $source_tables->{$_}{"partition_of"}
Aresult
11
00
650 4 my $part = $source_tables->{$key};
651 4 ▶ $taken{ $part->{schema_name} // '' }{ _partition_index_name($part->{table_name}, $entry->{index_info}{columns} // [], 'idx') } = 1;
Condition50%2/4
$part->{"schema_name"} // ""
l!l
40
$entry->{"index_info"}{"columns"} // []
l!l
40
MC/DC0%0/1
$part->{"schema_name"} // ""
$part->{"schema_name"}
MC/DC0%0/1
$entry->{"index_info"}{"columns"} // []
$entry->{"index_info"}{"columns"}
Truth table50%1/2
A
A= $part->{"schema_name"}
Aresult
11
00
Truth table50%1/2
A
A= $entry->{"index_info"}{"columns"}
Aresult
11
00
652 }
653 }
654  
655 # The indexes to put at the partitions when $tgt is the index of a
656 # partitioned table (karr k146): (partitions => \@tree), or nothing.
657 28 ▶ my $partitions = sub {
Subroutine __ANON__: called CC=8 SCAR=21.4
658 28 my ($tgt) = @_;
659 28 ▶ return unless (($target_tables->{ $tgt->{table_key} } // {})->{kind} // '') eq 'p';
Branch: 1 branch
BranchTrueFalseTotal
unless (+($$target_tables{$tgt->{"table_key"}} // {})->{"kind"} // "") eq "p" 21 7 28
Condition100%4/4
+($$target_tables{$tgt->{"table_key"}} // {})->{"kind"} // ""
l!l
244
$$target_tables{$tgt->{"table_key"}} // {}
l!l
271
MC/DC100%1/1
+($$target_tables{$tgt->{"table_key"}} // {})->{"kind"} // ""
$$target_tables{$tgt->{"table_key"}}
Truth table100%2/2
A
A= $$target_tables{$tgt->{"table_key"}}
Aresult
11
00
660 7 ▶ my $def = $tgt->{index_info}{definition} // '';
Condition50%1/2
$tgt->{"index_info"}{"definition"} // ""
l!l
70
MC/DC0%0/1
$tgt->{"index_info"}{"definition"} // ""
$tgt->{"index_info"}{"definition"}
Truth table50%1/2
A
A= $tgt->{"index_info"}{"definition"}
Aresult
11
00
661 7 ▶ return unless $def =~ /\A\s*CREATE\s+(?:UNIQUE\s+)?INDEX\s+$IDENT\s+ON\s+ONLY\s/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $def =~ /\A\s*CREATE\s+(?:UNIQUE\s+)?INDEX\s+$IDENT\s+ON\s+ONLY\s/i 0 7 7
662 7 ▶ my $tree = _partition_tree($source_tables, $target_tables, $tgt->{table_key}, $tgt->{index_info}, $def, \%taken)
Branch: 1 branch
BranchTrueFalseTotal
my $tree = _partition_tree($source_tables, $target_tables, $tgt->{"table_key"}, $tgt->{"index_info"}, $def, \%taken) or return 7 0 7
663 or return;
664 7 ▶ return @$tree ? (partitions => $tree) : ();
Branch: 1 branch
BranchTrueFalseTotal
@$tree ? : 7 0 7
665 124 };
666  
667 # An index to create, as the constraint it is the index of when the target
668 # says so, with the reasons it cannot be written that way collected.
669 66 ▶ my $create = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
670 66 my ($tgt) = @_;
671 66 my (undef, $type) = _constraint($tgt->{index_info}, $tgt->{index_name});
672 66 ▶ return $class->new(action => 'create', %$tgt, $partitions->($tgt)) unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 28 38 66
673 38 my @reasons = _create_reasons($tgt, $src_indexes);
674 38 ▶ push @constrained, [ $tgt, @reasons ] if @reasons;
Branch: 1 branch
BranchTrueFalseTotal
if @reasons 7 31 38
675 38 return $class->new(action => 'create', %$tgt, via => 'constraint');
676 124 };
677  
678 # New indexes
679 124 for my $tgt (_in_order($tgt_indexes)) {
680 109 ▶ my $src = $src_indexes->{ $tgt->{schema_name} // '' }{ $tgt->{index_name} };
Condition50%1/2
$tgt->{"schema_name"} // ""
l!l
1090
MC/DC0%0/1
$tgt->{"schema_name"} // ""
$tgt->{"schema_name"}
Truth table50%1/2
A
A= $tgt->{"schema_name"}
Aresult
11
00
681 109 ▶ my $tgt_def = $tgt->{index_info}{definition} // '';
Condition100%2/2
$tgt->{"index_info"}{"definition"} // ""
l!l
1036
MC/DC100%1/1
$tgt->{"index_info"}{"definition"} // ""
$tgt->{"index_info"}{"definition"}
Truth table100%2/2
A
A= $tgt->{"index_info"}{"definition"}
Aresult
11
00
682 109 ▶ if (!$src) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($src) 58 51 109
683 58 ▶ _refuse_without_definition($tgt, 0) unless $tgt_def =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tgt_def =~ /\S/ 2 56 58
684 # The constraint is there under another name, or its index is: the
685 # constraint takes it (karr k139).
686 56 ▶ if (my @take = $take_over->($tgt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@take) = &$take_over($tgt)) 11 45 56
687 11 push @ops, @take;
688 11 next;
689 }
690 # The same constraint under another name and another timing: dropped
691 # and created, not renamed (karr k147).
692 45 ▶ if (my $old = $retimed->($tgt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = &$retimed($tgt)) 3 42 45
693 3 ▶ $renamed{ $old->{schema_name} // '' }{ $old->{index_name} } = 1;
Condition50%1/2
$old->{"schema_name"} // ""
l!l
30
MC/DC0%0/1
$old->{"schema_name"} // ""
$old->{"schema_name"}
Truth table50%1/2
A
A= $old->{"schema_name"}
Aresult
11
00
694 3 my @reasons = _drop_reasons($old, 1, $fk);
695 3 ▶ push @constrained, [ $old, @reasons ] if @reasons;
Branch: 1 branch
BranchTrueFalseTotal
if @reasons 0 3 3
696 3 push @ops, $class->new(action => 'drop', %$old, replaced => 1), $create->($tgt);
697 3 next;
698 }
699 42 push @ops, $create->($tgt);
700 42 next;
701 }
702 # Changed indexes: compare definitions, and what the definition does not
703 # say (the constraint behind the index first of all)
704 51 ▶ my $src_def = $src->{index_info}{definition} // '';
Condition100%2/2
$src->{"index_info"}{"definition"} // ""
l!l
474
MC/DC100%1/1
$src->{"index_info"}{"definition"} // ""
$src->{"index_info"}{"definition"}
Truth table100%2/2
A
A= $src->{"index_info"}{"definition"}
Aresult
11
00
705 51 ▶ if ($src_def ne $tgt_def || _attributes_differ($src, $tgt)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src_def ne $tgt_def or _attributes_differ($src, $tgt)) 36 15 51
Condition100%3/3
$src_def ne $tgt_def or _attributes_differ($src, $tgt)
l!l&&r!l&&!r
181815
MC/DC100%2/2
$src_def ne $tgt_def or _attributes_differ($src, $tgt)
$src_def ne $tgt_def _attributes_differ($src, $tgt)
Truth table100%3/3
A or B
A= $src_def ne $tgt_defB= _attributes_differ($src, $tgt)
ABresult
1X1
011
000
706 36 ▶ _refuse_without_definition($tgt, 1) unless $tgt_def =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tgt_def =~ /\S/ 1 35 36
707 35 my (undef, $stype) = _constraint($src->{index_info}, $src->{index_name});
708 35 my (undef, $ttype) = _constraint($tgt->{index_info}, $tgt->{index_name});
709  
710 # The index is there, the constraint is not: the constraint takes the
711 # index it needs, ALTER TABLE ... ADD CONSTRAINT ... USING INDEX. Written
712 # without USING INDEX the server answers "relation already exists".
713 35 ▶ if (!defined $stype && defined $ttype && $ttype ne 'x' && $src_def eq $tgt_def) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $stype and defined $ttype and $ttype ne "x" and $src_def eq $tgt_def) 13 22 35
Condition88%8/9
not defined $stype and defined $ttype and $ttype ne "x" and $src_def eq $tgt_def
!ll&&!rl&&r
21113
not defined $stype and defined $ttype and $ttype ne "x"
!ll&&!rl&&r
21014
not defined $stype and defined $ttype
!ll&&!rl&&r
16514
MC/DC75%3/4
not defined $stype and defined $ttype and $ttype ne "x" and $src_def eq $tgt_def
not defined $stype defined $ttype $ttype ne "x" $src_def eq $tgt_def
Truth table80%4/5
not(A) and B and C and D
A= not defined $stypeB= defined $ttypeC= $ttype ne "x"D= $src_def eq $tgt_def
ABCDresult
0XXX0
10XX0
110X0
11100
11111
714 13 my @reasons = _using_index_reasons($src, $tgt, $source_tables, $src_indexes);
715 13 ▶ push @constrained, [ $tgt, @reasons ] if @reasons;
Branch: 1 branch
BranchTrueFalseTotal
if @reasons 9 4 13
716 13 push @ops, $class->new(action => 'create', %$tgt, via => 'using_index');
717 13 next;
718 }
719  
720 # Another index of the source is this constraint under another name, and
721 # the one that has the name is in its way (a nonunique index, or a
722 # constraint other than the target's): it goes first, then the other
723 # takes the name.
724 22 ▶ my @take = $src_def ne $tgt_def ? $take_over->($tgt) : ();
Branch: 1 branch
BranchTrueFalseTotal
$src_def ne $tgt_def ? : 17 5 22
725 22 ▶ if (defined $stype) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stype) 16 6 22
726 16 my @reasons = _drop_reasons($src, 1, $fk);
727 16 ▶ push @constrained, [ $src, @reasons ] if @reasons;
Branch: 1 branch
BranchTrueFalseTotal
if @reasons 3 13 16
728 }
729 22 push @ops, $class->new(action => 'drop', %$src, replaced => 1);
730 22 ▶ push @ops, @take ? @take : $create->($tgt);
Branch: 1 branch
BranchTrueFalseTotal
@take ? : 1 21 22
731 }
732 }
733  
734 # Dropped indexes
735 121 for my $src (_in_order($src_indexes)) {
736 111 ▶ next if $tgt_indexes->{ $src->{schema_name} // '' }{ $src->{index_name} };
Branch: 1 branch
BranchTrueFalseTotal
if $$tgt_indexes{$src->{"schema_name"} // ""}{$src->{"index_name"}} 50 61 111
Condition50%1/2
$src->{"schema_name"} // ""
l!l
1110
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
737 61 ▶ next if $renamed{ $src->{schema_name} // '' }{ $src->{index_name} };
Branch: 1 branch
BranchTrueFalseTotal
if $renamed{$src->{"schema_name"} // ""}{$src->{"index_name"}} 15 46 61
Condition50%1/2
$src->{"schema_name"} // ""
l!l
610
MC/DC0%0/1
$src->{"schema_name"} // ""
$src->{"schema_name"}
Truth table50%1/2
A
A= $src->{"schema_name"}
Aresult
11
00
738 # Skip when the owning table is itself being dropped this pass; the
739 # DROP TABLE already removes this index (karr k32).
740 46 ▶ next if $dropped_table{ $src->{table_key} };
Branch: 1 branch
BranchTrueFalseTotal
if $dropped_table{$src->{"table_key"}} 7 39 46
741 39 ▶ if (my @constraint = _constraint($src->{index_info}, $src->{index_name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@constraint) = _constraint($src->{'index_info'}, $src->{'index_name'})) { } 15 24 39
742 15 my @reasons = _drop_reasons($src, 0, $fk);
743 15 ▶ push @constrained, [ $src, @reasons ] if @reasons;
Branch: 1 branch
BranchTrueFalseTotal
if @reasons 8 7 15
744 }
745 else {
746 # an index without a constraint that a foreign key stands on
747 24 my @reasons = _drop_reasons($src, 0, $fk);
748 24 ▶ push @bound, [ $src, @reasons ] if @reasons;
Branch: 1 branch
BranchTrueFalseTotal
if @reasons 1 23 24
749 }
750 39 my @binds = _new_keys_bind($src, $source_fks, $target_fks);
751 39 ▶ push @bound, [ $src, @binds ] if @binds;
Branch: 1 branch
BranchTrueFalseTotal
if @binds 1 38 39
752 39 push @ops, $class->new(action => 'drop', %$src);
753 }
754  
755 121 _refuse_constraint(@constrained);
756 91 _refuse_bound(@bound);
757  
758 89 return @ops;
759 }
760  
761  
762 185 ▶sub as_sql {
Subroutine as_sql: called CC=27 SCAR=35.4
Pod documented
763 185 my ($self) = @_;
764 185 my @table =
765 DBIO::PostgreSQL::Introspect->key_names($self->table_key, table_name => $self);
766 # A key without a schema -- a model built by hand -- leaves the name alone.
767 185 ▶ my @schema = @table > 1 ? $table[0] : ();
Branch: 1 branch
BranchTrueFalseTotal
@table > 1 ? : 184 1 185
768  
769 185 ▶ my $action = $self->action // '';
Condition50%1/2
$self->action // ""
l!l
1850
MC/DC0%0/1
$self->action // ""
$self->action
Truth table50%1/2
A
A= $self->action
Aresult
11
00
770 185 ▶ my $info = $self->index_info // {};
Condition50%1/2
$self->index_info // {}
l!l
1850
MC/DC0%0/1
$self->index_info // {}
$self->index_info
Truth table50%1/2
A
A= $self->index_info
Aresult
11
00
771  
772 185 ▶ if ($action eq 'rename') {
Branch: 4 branches
BranchTrueFalseTotal
if ($action eq 'rename') { } 11 174 185
elsif ($action eq 'create' and defined $self->via) { } 39 135 174
elsif ($action eq 'create') { } 60 75 135
elsif ($action eq 'drop') { } 75 0 75
773 11 ▶ DBIO::PostgreSQL::Diff::NoStatement->throw($self, 'index ' . _name($self), 'it has no name to rename from')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->renamed_from and length $self->renamed_from 1 10 11
Condition66%2/3
defined $self->renamed_from and length $self->renamed_from
!ll&&!rl&&r
1010
MC/DC50%1/2
defined $self->renamed_from and length $self->renamed_from
defined $self->renamed_from length $self->renamed_from
Truth table66%2/3
A and B
A= defined $self->renamed_fromB= length $self->renamed_from
ABresult
0X0
100
111
774 unless defined $self->renamed_from && length $self->renamed_from;
775 10 ▶ return sprintf 'ALTER TABLE %s RENAME CONSTRAINT %s TO %s;',
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->via and $self->via eq "constraint" 3 7 10
Condition66%2/3
defined $self->via and $self->via eq "constraint"
!ll&&!rl&&r
703
MC/DC50%1/2
defined $self->via and $self->via eq "constraint"
defined $self->via $self->via eq "constraint"
Truth table66%2/3
A and B
A= defined $self->viaB= $self->via eq "constraint"
ABresult
0X0
100
111
776 quote_qualified(@table), quote_ident($self->renamed_from), quote_ident($self->index_name)
777 if defined $self->via && $self->via eq 'constraint';
778 7 return sprintf 'ALTER INDEX %s RENAME TO %s;',
779 quote_qualified(@schema, $self->renamed_from), quote_ident($self->index_name);
780 }
781 ▶ elsif ($action eq 'create' && defined $self->via) {
Condition100%3/3
$action eq "create" and defined $self->via
!ll&&!rl&&r
756039
MC/DC100%2/2
$action eq "create" and defined $self->via
$action eq "create" defined $self->via
Truth table100%3/3
A and B
A= $action eq "create"B= defined $self->via
ABresult
0X0
100
111
782 # A key of the table: the constraint, not the index behind it
783 39 my ($name, $type) = _constraint($info, $self->index_name);
784 39 my $object = 'constraint ' . _name($self);
785 39 ▶ DBIO::PostgreSQL::Diff::NoStatement->throw($self, $object, 'the class knows no such way to create it')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->via eq "constraint" or $self->via eq "using_index" 0 39 39
Condition66%2/3
$self->via eq "constraint" or $self->via eq "using_index"
l!l&&r!l&&!r
28110
MC/DC0%0/2
$self->via eq "constraint" or $self->via eq "using_index"
$self->via eq "constraint" $self->via eq "using_index"
Truth table66%2/3
A or B
A= $self->via eq "constraint"B= $self->via eq "using_index"
ABresult
1X1
011
000
786 unless $self->via eq 'constraint' || $self->via eq 'using_index';
787 39 ▶ DBIO::PostgreSQL::Diff::NoStatement->throw($self, $object,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type eq "p" || $type eq "u" 0 39 39
Condition50%3/6
defined $type and $type eq "p" || $type eq "u"
!ll&&!rl&&r
0039
$type eq "p" or $type eq "u"
l!l&&r!l&&!r
10290
MC/DC0%0/3
defined $type and $type eq "p" || $type eq "u"
defined $type $type eq "p" $type eq "u"
Truth table50%2/4
A and B or C
A= defined $typeB= $type eq "p"C= $type eq "u"
ABCresult
0XX0
1000
11X1
1011
788 'its index_info says no PRIMARY KEY or UNIQUE constraint stands behind it')
789 unless defined $type && ($type eq 'p' || $type eq 'u');
790  
791 return sprintf 'ALTER TABLE %s ADD CONSTRAINT %s %s USING INDEX %s%s;',
792 39 ▶ quote_qualified(@table), quote_ident($name), $CONSTRAINT_KIND{$type}, quote_ident($self->index_name),
Branch: 1 branch
BranchTrueFalseTotal
if $self->via eq "using_index" 11 28 39
793 _timing($info, $type)
794 if $self->via eq 'using_index';
795  
796 28 ▶ my @columns = @{ $info->{columns} // [] };
Condition50%1/2
$info->{"columns"} // []
l!l
280
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table50%1/2
A
A= $info->{"columns"}
Aresult
11
00
797 DBIO::PostgreSQL::Diff::NoStatement->throw($self, $object,
798 'its index_info has no columns to name, or one without a name, as an expression has none')
799 28 ▶ if !@columns || grep { !defined || !length } @columns;
Branch: 1 branch
BranchTrueFalseTotal
if not @columns or grep {not defined $_ && length $_;} @columns 0 28 28
Condition33%2/6
not @columns or grep {not defined $_ && length $_;} @columns
l!l&&r!l&&!r
0028
defined $_ && length $_
!ll&&!rl&&r
0036
MC/DC0%0/2
not @columns or grep {not defined $_ && length $_;} @columns
not @columns grep {not defined $_ && length $_;} @columns
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
not(A) or B
A= not @columnsB= grep {not defined $_ && length $_;} @columns
ABresult
1X1
011
000
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
800 28 return sprintf 'ALTER TABLE %s %s;', quote_qualified(@table), _add_constraint_sql($info, $name, $type);
801 }
802 elsif ($action eq 'create') {
803 # Use the full definition from introspection if available
804 60 my $def = $info->{definition};
805 60 ▶ return join "\n", "$def;", _partition_sql([ grep { defined } $self->schema_name, $self->index_name ], $self->partitions // [])
Branch: 1 branch
BranchTrueFalseTotal
if defined $def and $def =~ /\S/ 56 4 60
Condition80%4/5
defined $def and $def =~ /\S/
!ll&&!rl&&r
4056
$self->partitions // []
l!l
749
MC/DC50%1/2
defined $def and $def =~ /\S/
defined $def $def =~ /\S/
MC/DC100%1/1
$self->partitions // []
$self->partitions
Truth table66%2/3
A and B
A= defined $defB= $def =~ /\S/
ABresult
0X0
100
111
Truth table100%2/2
A
A= $self->partitions
Aresult
11
00
806 if defined $def && $def =~ /\S/;
807  
808 # The columns are not the index: unique, predicate, access method, order
809 # and operator class stand only in the definition.
810 4 DBIO::PostgreSQL::Diff::NoStatement->throw(
811 $self, 'index ' . _name($self),
812 'its index_info has no definition, and columns do not stand in for it: that the index is unique, its predicate, access method, order and operator class are in the definition only',
813 );
814 }
815 elsif ($action eq 'drop') {
816 # An index behind a constraint is dropped with the constraint: the server
817 # refuses DROP INDEX for it.
818 75 my ($constraint) = _constraint($info, $self->index_name);
819 75 ▶ return sprintf 'ALTER TABLE %s DROP CONSTRAINT %s;', quote_qualified(@table), quote_ident($constraint)
Branch: 1 branch
BranchTrueFalseTotal
if defined $constraint 19 56 75
820 if defined $constraint;
821 56 return sprintf 'DROP INDEX %s;', quote_qualified(@schema, $self->index_name);
822 }
823 0 DBIO::PostgreSQL::Diff::NoStatement->throw($self, 'index ' . _name($self));
824 }
825  
826  
827 12 ▶sub summary {
Subroutine summary: called CC=9 SCAR=22.2
Pod documented
828 12 my ($self) = @_;
829 12 ▶ return sprintf ' ~%s: %s -> %s (on %s)', (defined $self->via ? 'constraint' : 'index'),
Branch: 2 branches
BranchTrueFalseTotal
if ($self->action // "") eq "rename" 2 10 12
defined $self->via ? : 1 1 2
Condition50%2/4
$self->action // ""
l!l
120
$self->renamed_from // ""
l!l
20
MC/DC0%0/1
$self->action // ""
$self->action
MC/DC0%0/1
$self->renamed_from // ""
$self->renamed_from
Truth table50%1/2
A
A= $self->action
Aresult
11
00
Truth table50%1/2
A
A= $self->renamed_from
Aresult
11
00
830 $self->renamed_from // '', $self->index_name, $self->table_key
831 if ($self->action // '') eq 'rename';
832 10 ▶ my $prefix = $self->action eq 'create' ? '+' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$self->action eq 'create' ? : 8 2 10
833 10 ▶ my $kind = ($self->action eq 'create' ? defined $self->via : _constraint($self->index_info // {}, $self->index_name))
Branch: 2 branches
BranchTrueFalseTotal
($self->action eq 'create' ? defined $self->via : _constraint($self->index_info // {}, $self->index_name)) ? : 6 4 10
$self->action eq 'create' ? : 8 2 10
Condition50%1/2
$self->index_info // {}
l!l
20
MC/DC0%0/1
$self->index_info // {}
$self->index_info
Truth table50%1/2
A
A= $self->index_info
Aresult
11
00
834 ? 'constraint' : 'index';
835 10 return sprintf ' %s%s: %s (on %s)', $prefix, $kind, $self->index_name, $self->table_key;
836 }
837  
838 107 1;
839  
840 __END__
« blib/lib/DBIO/PostgreSQL/Diff/Function.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/OutsideReaders.pm »