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