blib/lib/SQL/Translator/Diff.pm

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