blib/lib/SQL/Translator/Diff.pm

filter: Statementstmt 93.0% 214 / 230 Branchbran 81.7% 67 / 82 Conditioncond 82.7% 24 / 29 MC/DCmcdc 68.7% 11 / 16 Subroutinesub 83.3% 15 / 18 Podpod 0.0% 0 / 10 totaltotal 85.9% 331 / 385 CC 70 SCAR 26.6
CC
70
Cov
89%
produce_diff_sql
27.8
diff_table_fields
12.2
compute_differences
11.1
CRAP 14.3
« blib/lib/SQL/Translator/Parser/Access.pm ↑ Summary blib/lib/SQL/Translator/Filter/Globals.pm »
1 package SQL::Translator::Diff;
2  
3 ## SQLT schema diffing code
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Carp::Clan qw/^SQL::Translator/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use SQL::Translator::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Sub::Quote qw(quote_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 15 has ignore_index_names => (is => 'rw',);
14 15 has ignore_constraint_names => (is => 'rw',);
15 15 has ignore_view_sql => (is => 'rw',);
16 15 has ignore_proc_sql => (is => 'rw',);
17 15 has output_db => (is => 'rw',);
18 15 has source_schema => (is => 'rw',);
19 15 has target_schema => (is => 'rw',);
20 15 has case_insensitive => (is => 'rw',);
21 15 has no_batch_alters => (is => 'rw',);
22 15 has ignore_missing_methods => (is => 'rw',);
23 15 has sqlt_args => (
24 is => 'rw',
25 lazy => 1,
26 default => quote_sub '{}',
27 );
28 15 has tables_to_drop => (
29 is => 'rw',
30 lazy => 1,
31 default => quote_sub '[]',
32 );
33 15 has tables_to_create => (
34 is => 'rw',
35 lazy => 1,
36 default => quote_sub '[]',
37 );
38 15 has table_diff_hash => (
39 is => 'rw',
40 lazy => 1,
41 default => quote_sub '{}',
42 );
43  
44 15 my @diff_arrays = qw/
45 tables_to_drop
46 tables_to_create
47 /;
48  
49 15 my @diff_hash_keys = qw/
50 constraints_to_create
51 constraints_to_drop
52 indexes_to_create
53 indexes_to_drop
54 fields_to_create
55 fields_to_alter
56 fields_to_rename
57 fields_to_drop
58 table_options
59 table_renamed_from
60 /;
61  
62 16 ▶sub schema_diff {
Subroutine schema_diff: called CC=2 SCAR=6.9
Pod undocumented
63  
64 # use Data::Dumper;
65 ## we are getting instructions on how to turn the source into the target
66 ## source == original, target == new (hmm, if I need to comment this, should I rename the vars again ??)
67 ## _schema isa SQL::Translator::Schema
68 ## _db is the name of the producer/db it came out of/into
69 ## results are formatted to the source preferences
70  
71 16 my ($source_schema, $source_db, $target_schema, $output_db, $options) = @_;
72 16 ▶ $options ||= {};
Condition100%2/2
$options ||= {}
l!l
115
MC/DC100%1/1
$options ||= {}
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
73  
74 16 my $obj = SQL::Translator::Diff->new({
75 %$options,
76 source_schema => $source_schema,
77 target_schema => $target_schema,
78 output_db => $output_db
79 });
80  
81 16 $obj->compute_differences->produce_diff_sql;
82 }
83  
84 15 my $warned_dep;
85  
86 24 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=20.2
Pod undocumented
87 24 my ($self, $args) = @_;
88 24 for my $deprecated (qw/producer_options producer_args/) {
89 48 ▶ if ($args->{$deprecated}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{$deprecated}) 0 48 48
90 0 ▶ carp
Branch: 1 branch
BranchTrueFalseTotal
unless $warned_dep++ 0 0 0
91 "$deprecated is deprecated -- it does not go straight to the producer, it goes to the internal sqlt object. Please use sqlt_args, which reflects how it's used"
92 unless $warned_dep++;
93 0 $self->sqlt_args({ %{ $args->{$deprecated} }, %{ $self->sqlt_args } });
94 }
95 }
96  
97 24 ▶ if (!$self->output_db) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->output_db) 3 21 24
98 3 $self->output_db($args->{source_db});
99 }
100 }
101  
102 24 ▶sub compute_differences {
Subroutine compute_differences: called CC=11 SCAR=24.1
Pod undocumented
103 24 my ($self) = @_;
104  
105 24 my $target_schema = $self->target_schema;
106 24 my $source_schema = $self->source_schema;
107  
108 24 my $producer_class = "SQL::Translator::Producer::@{[$self->output_db]}";
109 24 eval "require $producer_class";
110 24 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 24 24
111  
112 24 ▶ if (my $preprocess = $producer_class->can('preprocess_schema')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $preprocess = $producer_class->can("preprocess_schema")) 14 10 24
113 14 $preprocess->($source_schema);
114 14 $preprocess->($target_schema);
115 }
116  
117 24 my %src_tables_checked = ();
118 24 my @tar_tables = sort { $a->name cmp $b->name } $target_schema->get_tables;
119 ## do original/source tables exist in target?
120 24 for my $tar_table (@tar_tables) {
121 78 my $tar_table_name = $tar_table->name;
122  
123 78 my $src_table;
124  
125 78 $self->table_diff_hash->{$tar_table_name} = { map { $_ => [] } @diff_hash_keys };
126  
127 78 ▶ if (my $old_name = $tar_table->extra('renamed_from')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old_name = $tar_table->extra('renamed_from')) { } 10 68 78
128 10 $src_table = $source_schema->get_table($old_name, $self->case_insensitive);
129 10 ▶ if ($src_table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src_table) { } 10 0 10
130 10 $self->table_diff_hash->{$tar_table_name}{table_renamed_from} = [ [ $src_table, $tar_table ] ];
131 } else {
132 0 delete $tar_table->extra->{renamed_from};
133 0 carp qq#Renamed table can't find old table "$old_name" for renamed table\n#;
134 }
135 } else {
136 68 $src_table = $source_schema->get_table($tar_table_name, $self->case_insensitive);
137 }
138  
139 78 ▶ unless ($src_table) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($src_table) 12 66 78
140 ## table is new
141 ## add table(s) later.
142 12 push @{ $self->tables_to_create }, $tar_table;
143 12 next;
144 }
145  
146 66 my $src_table_name = $src_table->name;
147 66 ▶ $src_table_name = lc $src_table_name if $self->case_insensitive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->case_insensitive 0 66 66
148 66 $src_tables_checked{$src_table_name} = 1;
149  
150 66 $self->diff_table_options($src_table, $tar_table);
151  
152 ## Compare fields, their types, defaults, sizes etc etc
153 66 $self->diff_table_fields($src_table, $tar_table);
154  
155 66 $self->diff_table_indexes($src_table, $tar_table);
156 66 $self->diff_table_constraints($src_table, $tar_table);
157  
158 } # end of target_schema->get_tables loop
159  
160 24 for my $src_table ($source_schema->get_tables) {
161 81 my $src_table_name = $src_table->name;
162  
163 81 ▶ $src_table_name = lc $src_table_name if $self->case_insensitive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->case_insensitive 0 81 81
164  
165 15 push @{ $self->tables_to_drop }, $src_table
166 81 ▶ unless $src_tables_checked{$src_table_name};
Branch: 1 branch
BranchTrueFalseTotal
unless $src_tables_checked{$src_table_name} 15 66 81
167 }
168  
169 24 return $self;
170 }
171  
172 21 ▶sub produce_diff_sql {
Subroutine produce_diff_sql: called CC=27 SCAR=33.3
Pod undocumented
173 21 my ($self) = @_;
174  
175 21 my $target_schema = $self->target_schema;
176 21 my $source_schema = $self->source_schema;
177 21 my $tar_name = $target_schema->name;
178 21 my $src_name = $source_schema->name;
179  
180 21 my $producer_class = "SQL::Translator::Producer::@{[$self->output_db]}";
181 21 eval "require $producer_class";
182 21 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 21 21
183  
184 # Map of name we store under => producer method name
185 21 my %func_map = (
186 constraints_to_create => 'alter_create_constraint',
187 constraints_to_drop => 'alter_drop_constraint',
188 indexes_to_create => 'alter_create_index',
189 indexes_to_drop => 'alter_drop_index',
190 fields_to_create => 'add_field',
191 fields_to_alter => 'alter_field',
192 fields_to_rename => 'rename_field',
193 fields_to_drop => 'drop_field',
194 table_options => 'alter_table',
195 table_renamed_from => 'rename_table',
196 );
197 21 my @diffs;
198  
199 21 ▶ if (!$self->no_batch_alters
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->no_batch_alters and my $batch_alter = $producer_class->can('batch_alter_table')) { } 15 6 21
Condition100%3/3
not $self->no_batch_alters and my $batch_alter = $producer_class->can("batch_alter_table")
!ll&&!rl&&r
2415
MC/DC100%2/2
not $self->no_batch_alters and my $batch_alter = $producer_class->can("batch_alter_table")
not $self->no_batch_alters my $batch_alter = $producer_class->can("batch_alter_table")
Truth table100%3/3
not(A) and B
A= not $self->no_batch_altersB= my $batch_alter = $producer_class->can("batch_alter_table")
ABresult
0X0
100
111
200 && (my $batch_alter = $producer_class->can('batch_alter_table'))) {
201 # Good - Producer supports batch altering of tables.
202 15 foreach my $table (sort keys %{ $self->table_diff_hash }) {
203 44 ▶ my $tar_table = $target_schema->get_table($table)
Condition33%1/3
$target_schema->get_table($table) || $source_schema->get_table($table)
l!l&&r!l&&!r
4400
MC/DC0%0/2
$target_schema->get_table($table) || $source_schema->get_table($table)
$target_schema->get_table($table) $source_schema->get_table($table)
Truth table33%1/3
A || B
A= $target_schema->get_table($table)B= $source_schema->get_table($table)
ABresult
1X1
011
000
204 || $source_schema->get_table($table);
205  
206 push @diffs,
207 $batch_alter->(
208 $tar_table,
209 {
210 44 map { $func_map{$_} => $self->table_diff_hash->{$table}{$_} } keys %func_map
211 },
212 $self->sqlt_args
213 );
214 }
215 } else {
216  
217 # If we have any table renames we need to do those first;
218 6 my %flattened_diffs;
219 6 foreach my $table (sort keys %{ $self->table_diff_hash }) {
220 22 my $table_diff = $self->table_diff_hash->{$table};
221 22 for (@diff_hash_keys) {
222 220 ▶ push(@{ $flattened_diffs{ $func_map{$_} } ||= [] }, @{ $table_diff->{$_} });
Condition100%2/2
$flattened_diffs{$func_map{$_}} ||= []
l!l
16060
MC/DC100%1/1
$flattened_diffs{$func_map{$_}} ||= []
$flattened_diffs{$func_map{$_}}
Truth table100%2/2
A
A= $flattened_diffs{$func_map{$_}}
Aresult
11
00
223 }
224 }
225  
226 push @diffs, map({
227 6 ▶ if (@{ $flattened_diffs{$_} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$flattened_diffs{$_} or [];}) { } 34 26 60
Condition50%1/2
$flattened_diffs{$_} || []
l!l
600
MC/DC0%0/1
$flattened_diffs{$_} || []
$flattened_diffs{$_}
Truth table50%1/2
A
A= $flattened_diffs{$_}
Aresult
11
00
228 34 my $meth = $producer_class->can($_);
229  
230 $meth
231 ? map {
232 52 ▶ map { $_ ? "$_" : () } $meth->((ref $_ eq 'ARRAY' ? @$_ : $_), $self->sqlt_args);
Branch: 2 branches
BranchTrueFalseTotal
$_ ? : 50 1 51
ref $_ eq 'ARRAY' ? : 11 41 52
233 34 ▶ } @{ $flattened_diffs{$_} }
Branch: 2 branches
BranchTrueFalseTotal
$meth ? : 31 3 34
$self->ignore_missing_methods ? : 3 0 3
234 : $self->ignore_missing_methods ? "-- $producer_class cant $_"
235 : die "$producer_class cant $_";
236 } else {
237 ()
238 26 }
239  
240 } qw/rename_table
241 alter_drop_constraint
242 alter_drop_index
243 drop_field
244 add_field
245 alter_field
246 rename_field
247 alter_create_index
248 alter_create_constraint
249 alter_table/),
250 ;
251 }
252  
253 21 ▶ if (my @tables = @{ $self->tables_to_create }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@tables) = @{$self->tables_to_create;}) 10 11 21
254 my $translator = SQL::Translator->new(
255 producer_type => $self->output_db,
256 add_drop_table => 0,
257 no_comments => 1,
258  
259 # TODO: sort out options
260 10 %{ $self->sqlt_args }
261 );
262 10 $translator->producer_args->{no_transaction} = 1;
263 10 my $schema = $translator->schema;
264  
265 10 $schema->add_table($_) for @tables;
266  
267 unshift @diffs,
268  
269 # Remove begin/commit here, since we wrap everything in one.
270 10 grep { $_ !~ /^(?:COMMIT|START(?: TRANSACTION)?|BEGIN(?: TRANSACTION)?)/ }
271 $producer_class->can('produce')->($translator);
272 }
273  
274 21 ▶ if (my @tables_to_drop = @{ $self->{tables_to_drop} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@tables_to_drop) = @{$self->{"tables_to_drop"} or [];}) 13 8 21
Condition100%2/2
$self->{'tables_to_drop'} || []
l!l
138
MC/DC100%1/1
$self->{'tables_to_drop'} || []
$self->{'tables_to_drop'}
Truth table100%2/2
A
A= $self->{'tables_to_drop'}
Aresult
11
00
275 13 my $meth = $producer_class->can('drop_table');
276  
277 push @diffs,
278 13 ▶ $meth ? (map { $meth->($_, $self->sqlt_args) } @tables_to_drop)
Branch: 2 branches
BranchTrueFalseTotal
$meth ? : 13 0 13
$self->ignore_missing_methods ? : 0 0 0
279 : $self->ignore_missing_methods ? "-- $producer_class cant drop_table"
280 : die "$producer_class cant drop_table";
281 }
282  
283 21 ▶ if (@diffs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@diffs) { } 17 4 21
284 17 unshift @diffs, "BEGIN";
285 17 push @diffs, "\nCOMMIT";
286 } else {
287 4 @diffs = ("-- No differences found");
288 }
289  
290 21 ▶ if (@diffs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@diffs) 21 0 21
291 21 ▶ if ($self->output_db !~ /^(?:MySQL|SQLite|PostgreSQL)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->output_db =~ /^(?:MySQL|SQLite|PostgreSQL)$/) 4 17 21
292 4 unshift(@diffs, "-- Output database @{[$self->output_db]} is untested/unsupported!!!");
293 }
294  
295 21 ▶ my @return = map { $_ ? ($_ =~ /;\s*\z/xms ? $_ : "$_;\n\n") : "\n" }
Branch: 2 branches
BranchTrueFalseTotal
$_ ? : 224 0 224
$_ =~ /;\s*\z/msx ? : 2 222 224
296 ("-- Convert schema '$src_name' to '$tar_name':", @diffs);
297  
298 21 ▶ return wantarray ? @return : join('', @return);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 20 21
299 }
300 0 return undef;
301  
302 }
303  
304 66 ▶sub diff_table_indexes {
Subroutine diff_table_indexes: called CC=9 SCAR=22.0
Pod undocumented
305 66 my ($self, $src_table, $tar_table) = @_;
306  
307 66 my (%checked_indices);
308 INDEX_CREATE:
309 66 for my $i_tar ($tar_table->get_indices) {
310 24 for my $i_src ($src_table->get_indices) {
311 27 ▶ if ($i_tar->equals($i_src, $self->case_insensitive, $self->ignore_index_names)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tar->equals($i_src, $self->case_insensitive, $self->ignore_index_names)) 16 11 27
312 16 $checked_indices{$i_src} = 1;
313 16 next INDEX_CREATE;
314 }
315 }
316 8 push @{ $self->table_diff_hash->{$tar_table}{indexes_to_create} }, $i_tar;
317 }
318  
319 INDEX_DROP:
320 66 for my $i_src ($src_table->get_indices) {
321 24 ▶ next if !$self->ignore_index_names && $checked_indices{$i_src};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->ignore_index_names and $checked_indices{$i_src} 12 12 24
Condition100%3/3
not $self->ignore_index_names and $checked_indices{$i_src}
!ll&&!rl&&r
4812
MC/DC100%2/2
not $self->ignore_index_names and $checked_indices{$i_src}
not $self->ignore_index_names $checked_indices{$i_src}
Truth table100%3/3
not(A) and B
A= not $self->ignore_index_namesB= $checked_indices{$i_src}
ABresult
0X0
100
111
322 12 for my $i_tar ($tar_table->get_indices) {
323 next INDEX_DROP
324 12 ▶ if $i_src->equals($i_tar, $self->case_insensitive, $self->ignore_index_names);
Branch: 1 branch
BranchTrueFalseTotal
if $i_src->equals($i_tar, $self->case_insensitive, $self->ignore_index_names) 4 8 12
325 }
326 8 push @{ $self->table_diff_hash->{$tar_table}{indexes_to_drop} }, $i_src;
327 }
328 }
329  
330 66 ▶sub diff_table_constraints {
Subroutine diff_table_constraints: called CC=9 SCAR=22.0
Pod undocumented
331 66 my ($self, $src_table, $tar_table) = @_;
332  
333 66 my (%checked_constraints);
334 CONSTRAINT_CREATE:
335 66 for my $c_tar ($tar_table->get_constraints) {
336 131 for my $c_src ($src_table->get_constraints) {
337  
338 # This is a bit of a hack - needed for renaming tables to work
339 221 local $c_src->{table} = $tar_table;
340  
341 221 ▶ if ($c_tar->equals($c_src, $self->case_insensitive, $self->ignore_constraint_names)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c_tar->equals($c_src, $self->case_insensitive, $self->ignore_constraint_names)) 91 130 221
342 91 $checked_constraints{$c_src} = 1;
343 91 next CONSTRAINT_CREATE;
344 }
345 }
346 40 push @{ $self->table_diff_hash->{$tar_table}{constraints_to_create} }, $c_tar;
347 }
348  
349 CONSTRAINT_DROP:
350 66 for my $c_src ($src_table->get_constraints) {
351  
352 # This is a bit of a hack - needed for renaming tables to work
353 125 local $c_src->{table} = $tar_table;
354  
355 125 ▶ next if !$self->ignore_constraint_names && $checked_constraints{$c_src};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->ignore_constraint_names and $checked_constraints{$c_src} 75 50 125
Condition100%3/3
not $self->ignore_constraint_names and $checked_constraints{$c_src}
!ll&&!rl&&r
212975
MC/DC100%2/2
not $self->ignore_constraint_names and $checked_constraints{$c_src}
not $self->ignore_constraint_names $checked_constraints{$c_src}
Truth table100%3/3
not(A) and B
A= not $self->ignore_constraint_namesB= $checked_constraints{$c_src}
ABresult
0X0
100
111
356 50 for my $c_tar ($tar_table->get_constraints) {
357 next CONSTRAINT_DROP
358 106 ▶ if $c_src->equals($c_tar, $self->case_insensitive, $self->ignore_constraint_names);
Branch: 1 branch
BranchTrueFalseTotal
if $c_src->equals($c_tar, $self->case_insensitive, $self->ignore_constraint_names) 16 90 106
359 }
360  
361 34 push @{ $self->table_diff_hash->{$tar_table}{constraints_to_drop} }, $c_src;
362 }
363  
364 }
365  
366 66 ▶sub diff_table_fields {
Subroutine diff_table_fields: called CC=12 SCAR=25.0
Pod undocumented
367 66 my ($self, $src_table, $tar_table) = @_;
368  
369 # List of ones we've renamed from so we don't drop them
370 66 my %renamed_source_fields;
371  
372 66 for my $tar_table_field ($tar_table->get_fields) {
373 269 my $f_tar_name = $tar_table_field->name;
374  
375 269 ▶ if (my $old_name = $tar_table_field->extra->{renamed_from}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old_name = $tar_table_field->extra->{"renamed_from"}) 9 260 269
376 9 my $src_table_field = $src_table->get_field($old_name, $self->case_insensitive);
377 9 ▶ unless ($src_table_field) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src_table_field) { } 9 0 9
378 0 carp qq#Renamed column can't find old column "@{[$src_table->name]}.$old_name" for renamed column\n#;
379 0 delete $tar_table_field->extra->{renamed_from};
380 } else {
381 9 push @{ $self->table_diff_hash->{$tar_table}{fields_to_rename} }, [ $src_table_field, $tar_table_field ];
382 9 $renamed_source_fields{$old_name} = 1;
383 9 next;
384 }
385 }
386  
387 260 my $src_table_field = $src_table->get_field($f_tar_name, $self->case_insensitive);
388  
389 260 ▶ unless ($src_table_field) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($src_table_field) 28 232 260
390 28 push @{ $self->table_diff_hash->{$tar_table}{fields_to_create} }, $tar_table_field;
391 28 next;
392 }
393  
394 # field exists, something changed. This is a bit complex. Parsers can
395 # normalize types, but only some of them do, so compare the normalized and
396 # parsed types for each field to each other
397 232 ▶ if ( !$tar_table_field->equals($src_table_field, $self->case_insensitive)
Branch: 1 branch
BranchTrueFalseTotal
unless ($tar_table_field->equals($src_table_field, $self->case_insensitive) or $tar_table_field->equals($src_table_field->parsed_field, $self->case_insensitive) or $tar_table_field->parsed_field->equals($src_table_field, $self->case_insensitive) or $tar_table_field->parsed_field->equals($src_table_field->parsed_field, $self->case_insensitive)) 52 180 232
Condition77%7/9
$tar_table_field->equals($src_table_field, $self->case_insensitive) or $tar_table_field->equals($src_table_field->parsed_field, $self->case_insensitive) or $tar_table_field->parsed_field->equals($src_table_field, $self->case_insensitive) or $tar_table_field->parsed_field->equals($src_table_field->parsed_field, $self->case_insensitive)
l!l&&r!l&&!r
180052
$tar_table_field->equals($src_table_field, $self->case_insensitive) or $tar_table_field->equals($src_table_field->parsed_field, $self->case_insensitive) or $tar_table_field->parsed_field->equals($src_table_field, $self->case_insensitive)
l!l&&r!l&&!r
180052
$tar_table_field->equals($src_table_field, $self->case_insensitive) or $tar_table_field->equals($src_table_field->parsed_field, $self->case_insensitive)
l!l&&r!l&&!r
179152
MC/DC50%2/4
$tar_table_field->equals($src_table_field, $self->case_insensitive) or $tar_table_field->equals($src_table_field->parsed_field, $self->case_insensitive) or $tar_table_field->parsed_field->equals($src_table_field, $self->case_insensitive) or $tar_table_field->parsed_field->equals($src_table_field->parsed_field, $self->case_insensitive)
$tar_table_field->equals($src_table_field, $self->case_insensitive) $tar_table_field->equals($src_table_field->parsed_field, $self->case_insensitive) $tar_table_field->parsed_field->equals($src_table_field, $self->case_insensitive) $tar_table_field->parsed_field->equals($src_table_field->parsed_field, $self->case_insensitive)
Truth table60%3/5
A or B or C or D
A= $tar_table_field->equals($src_table_field, $self->case_insensitive)B= $tar_table_field->equals($src_table_field->parsed_field, $self->case_insensitive)C= $tar_table_field->parsed_field->equals($src_table_field, $self->case_insensitive)D= $tar_table_field->parsed_field->equals($src_table_field->parsed_field, $self->case_insensitive)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
398 && !$tar_table_field->equals($src_table_field->parsed_field, $self->case_insensitive)
399 && !$tar_table_field->parsed_field->equals($src_table_field, $self->case_insensitive)
400 && !$tar_table_field->parsed_field->equals($src_table_field->parsed_field, $self->case_insensitive)) {
401  
402 # Some producers might need src field to diff against
403 52 push @{ $self->table_diff_hash->{$tar_table}{fields_to_alter} }, [ $src_table_field, $tar_table_field ];
404 52 next;
405 }
406 }
407  
408 # Now check to see if any fields from src_table need to be dropped
409 66 for my $src_table_field ($src_table->get_fields) {
410 257 my $f_src_name = $src_table_field->name;
411 257 ▶ next if $renamed_source_fields{$f_src_name};
Branch: 1 branch
BranchTrueFalseTotal
if $renamed_source_fields{$f_src_name} 9 248 257
412  
413 248 my $tar_table_field = $tar_table->get_field($f_src_name, $self->case_insensitive);
414  
415 248 ▶ unless ($tar_table_field) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tar_table_field) 16 232 248
416 16 push @{ $self->table_diff_hash->{$tar_table}{fields_to_drop} }, $src_table_field;
417 16 next;
418 }
419 }
420 }
421  
422 66 ▶sub diff_table_options {
Subroutine diff_table_options: called CC=2 SCAR=7.1
Pod undocumented
423 66 my ($self, $src_table, $tar_table) = @_;
424  
425 0 ▶ my $cmp = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
426 0 my ($a_name, undef, $b_name, undef) = (%$a, %$b);
427 0 $a_name cmp $b_name;
428 66 };
429  
430 # Need to sort the options so we don't get spurious diffs.
431 66 my (@src_opts, @tar_opts);
432 66 @src_opts = sort $cmp $src_table->options;
433 66 @tar_opts = sort $cmp $tar_table->options;
434  
435 # If there's a difference, just re-set all the options
436 66 ▶ push @{ $self->table_diff_hash->{$tar_table}{table_options} }, $tar_table
Branch: 1 branch
BranchTrueFalseTotal
unless $src_table->_compare_objects(\@src_opts, \@tar_opts) 9 57 66
437 unless $src_table->_compare_objects(\@src_opts, \@tar_opts);
438 }
439  
440 # support producer_options as an alias for sqlt_args for legacy code.
441 0 ▶sub producer_options {
Subroutine producer_options: not called CC=1 SCAR=6.9
Pod undocumented
442 0 my $self = shift;
443  
444 0 return $self->sqlt_args(@_);
445 }
446  
447 # support producer_args as an alias for sqlt_args for legacy code.
448 0 ▶sub producer_args {
Subroutine producer_args: not called CC=1 SCAR=6.9
Pod undocumented
449 0 my $self = shift;
450  
451 0 return $self->sqlt_args(@_);
452 }
453  
454 15 1;
455  
456 __END__
« blib/lib/SQL/Translator/Parser/Access.pm ↑ Summary blib/lib/SQL/Translator/Filter/Globals.pm »