| 1 | package DBIO::Oracle::Diff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Compare two introspected Oracle models | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 30 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 30 | ▶ | use base 'DBIO::Diff::Base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 30 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 30 | ▶ | use DBIO::Oracle::Diff::Table (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 30 | ▶ | use DBIO::Oracle::Diff::Column (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 30 | ▶ | use DBIO::Oracle::Diff::Index (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 30 | ▶ | use DBIO::Oracle::Diff::ForeignKey (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 30 | ▶ | use DBIO::Oracle::Diff::Unique (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 30 | ▶ | use DBIO::Oracle::Diff::View (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 30 | my %_REGISTRY = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | tables => 'DBIO::Oracle::Diff::Table', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | columns => 'DBIO::Oracle::Diff::Column', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | indexes => 'DBIO::Oracle::Diff::Index', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 30 | my @_ORDER = qw(tables columns indexes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # The sections of the models a kind of operation is built from besides its own: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # which tables the models have, to tell a table both have from a new one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 30 | my %_NEEDS_TABLES = map { $_ => 1 } qw(columns indexes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 121 | ▶ | sub _build_operations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_operations: called CC=31 SCAR=34.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 121 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 121 | my (@ops, @gone_fk, @gone_unique, @new_unique, @new_fk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 121 | my ($src, $tgt) = ($self->source, $self->target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Foreign keys and unique constraints (karr k64): the ones that are gone are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # dropped before anything else happens to tables and columns, the new ones | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # are added after it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 121 | ▶ | my @tables = ($src->{tables} // {}, $tgt->{tables} // {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$src->{"tables"} // {}
$tgt->{"tables"} // {}
MC/DC100%1/1
$src->{"tables"} // {}
$src->{"tables"}
MC/DC0%0/1
$tgt->{"tables"} // {}
$tgt->{"tables"}
Truth table100%2/2
A
A= $src->{"tables"}
Truth table50%1/2
A
A= $tgt->{"tables"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | my @fk = DBIO::Oracle::Diff::ForeignKey->diff( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | $src->{foreign_keys} // {}, $tgt->{foreign_keys} // {}, @tables, $tgt->{columns} // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 121 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$src->{"foreign_keys"} // {}
$tgt->{"foreign_keys"} // {}
$tgt->{"columns"} // {}
MC/DC100%1/1
$src->{"foreign_keys"} // {}
$src->{"foreign_keys"}
MC/DC100%1/1
$tgt->{"foreign_keys"} // {}
$tgt->{"foreign_keys"}
MC/DC100%1/1
$tgt->{"columns"} // {}
$tgt->{"columns"}
Truth table100%2/2
A
A= $src->{"foreign_keys"}
Truth table100%2/2
A
A= $tgt->{"foreign_keys"}
Truth table100%2/2
A
A= $tgt->{"columns"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | my @uq = DBIO::Oracle::Diff::Unique->diff( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | $src->{unique_constraints} // {}, $tgt->{unique_constraints} // {}, @tables, $tgt->{columns} // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 118 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$src->{"unique_constraints"} // {}
$tgt->{"unique_constraints"} // {}
$tgt->{"columns"} // {}
MC/DC100%1/1
$src->{"unique_constraints"} // {}
$src->{"unique_constraints"}
MC/DC100%1/1
$tgt->{"unique_constraints"} // {}
$tgt->{"unique_constraints"}
MC/DC100%1/1
$tgt->{"columns"} // {}
$tgt->{"columns"}
Truth table100%2/2
A
A= $src->{"unique_constraints"}
Truth table100%2/2
A
A= $tgt->{"unique_constraints"}
Truth table100%2/2
A
A= $tgt->{"columns"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 118 | @gone_fk = grep { $_->action eq 'drop' } @fk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 118 | @new_fk = grep { $_->action eq 'create' } @fk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 118 | @gone_unique = grep { $_->action eq 'drop' } @uq; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 118 | @new_unique = grep { $_->action eq 'create' } @uq; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # A key that stays over a unique constraint the target drops or changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # (ORA-02273, karr k64) goes first and is created again, unchanged, after. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 118 | my ($again_drop, $again_new) = $self->_keys_over_gone_unique(\@gone_unique); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 116 | push @gone_fk, @$again_drop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 116 | push @new_fk, @$again_new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Views (karr k65): the ones that are gone are dropped before the tables they | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # rest on are touched, the new and changed ones written after everything else. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | my @views = DBIO::Oracle::Diff::View->diff( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | @tables, $src->{views} // {}, $tgt->{views} // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 116 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$src->{"views"} // {}
$tgt->{"views"} // {}
MC/DC100%1/1
$src->{"views"} // {}
$src->{"views"}
MC/DC100%1/1
$tgt->{"views"} // {}
$tgt->{"views"}
Truth table100%2/2
A
A= $src->{"views"}
Truth table100%2/2
A
A= $tgt->{"views"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 106 | my @gone_view = grep { $_->action eq 'drop' } @views; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 106 | my @new_view = grep { $_->action ne 'drop' } @views; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 106 | push @ops, @gone_fk, @gone_unique, @gone_view; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 106 | for my $key (@_ORDER) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 308 | ▶ | my $diff_cls = $_REGISTRY{$key} or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 308 | ▶ | next unless exists $src->{$key} || exists $tgt->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $src->{$key} or exists $tgt->{$key}
MC/DC100%2/2
exists $src->{$key} or exists $tgt->{$key}
exists $src->{$key}
exists $tgt->{$key}
Truth table100%3/3
A or B
A= exists $src->{$key}B= exists $tgt->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 246 | my @extra; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 246 | ▶ | if ($_NEEDS_TABLES{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 140 | @extra = @tables; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | elsif ($key eq 'tables') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # what a table only the target has is created from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | @extra = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | $tgt->{columns} // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | $tgt->{unique_constraints} // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | $src->{columns} // {}, # the sequences of a dropped table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 106 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$tgt->{"columns"} // {}
$tgt->{"unique_constraints"} // {}
$src->{"columns"} // {}
MC/DC100%1/1
$tgt->{"columns"} // {}
$tgt->{"columns"}
MC/DC100%1/1
$tgt->{"unique_constraints"} // {}
$tgt->{"unique_constraints"}
MC/DC100%1/1
$src->{"columns"} // {}
$src->{"columns"}
Truth table100%2/2
A
A= $tgt->{"columns"}
Truth table100%2/2
A
A= $tgt->{"unique_constraints"}
Truth table100%2/2
A
A= $src->{"columns"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | push @ops, $diff_cls->diff( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | $src->{$key} // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 246 | ▶ | $tgt->{$key} // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$src->{$key} // {}
$tgt->{$key} // {}
MC/DC100%1/1
$src->{$key} // {}
$src->{$key}
MC/DC0%0/1
$tgt->{$key} // {}
$tgt->{$key}
Truth table100%2/2
A
A= $src->{$key}
Truth table50%1/2
A
A= $tgt->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | @extra, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 101 | push @ops, @new_unique, @new_fk, @new_view; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # An index goes with a column it is on (ALTER TABLE ... DROP COLUMN): a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # DROP INDEX after that fails with ORA-01418, so it is not written (karr k63). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 101 | my %dropped; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 101 | for my $op (@ops) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 141 | ▶ | next unless $op->isa('DBIO::Oracle::Diff::Column') && $op->action eq 'drop'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$op->isa("DBIO::Oracle::Diff::Column") and $op->action eq "drop"
MC/DC100%2/2
$op->isa("DBIO::Oracle::Diff::Column") and $op->action eq "drop"
$op->isa("DBIO::Oracle::Diff::Column")
$op->action eq "drop"
Truth table100%3/3
A and B
A= $op->isa("DBIO::Oracle::Diff::Column")B= $op->action eq "drop"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | $dropped{ $op->table_name }{ $op->column_name } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 101 | ▶ | if (%dropped) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | @ops = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | my $op = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | !( $op->isa('DBIO::Oracle::Diff::Index') && $op->action eq 'drop' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | && $dropped{ $op->table_name } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | ▶ | && grep { $dropped{ $op->table_name }{$_} } @{ ($op->index_info // {})->{columns} // [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition61%8/13
$op->isa('DBIO::Oracle::Diff::Index') && $op->action eq 'drop' && $dropped{$op->table_name} && grep({$dropped{$op->table_name}{$_};} @{+($op->index_info // {})->{'columns'} // [];})
$op->isa("DBIO::Oracle::Diff::Index") and $op->action eq "drop" and $dropped{$op->table_name}
$op->isa("DBIO::Oracle::Diff::Index") and $op->action eq "drop"
+($op->index_info // {})->{"columns"} // []
$op->index_info // {}
MC/DC25%1/4
$op->isa('DBIO::Oracle::Diff::Index') && $op->action eq 'drop' && $dropped{$op->table_name} && grep({$dropped{$op->table_name}{$_};} @{+($op->index_info // {})->{'columns'} // [];})
$op->isa("DBIO::Oracle::Diff::Index")
$op->action eq "drop"
$dropped{$op->table_name}
grep({$dropped{$op->table_name}{$_};} @{+($op->index_info // {})->{'columns'} // [];})
MC/DC0%0/1
+($op->index_info // {})->{"columns"} // []
$op->index_info
Truth table40%2/5
A and B and C && D
A= $op->isa("DBIO::Oracle::Diff::Index")B= $op->action eq "drop"C= $dropped{$op->table_name}D= grep({$dropped{$op->table_name}{$_};} @{+($op->index_info // {})->{'columns'} // [];})
Truth table50%1/2
A
A= $op->index_info
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } @ops; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 101 | return \@ops; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # The foreign keys that stay as they are over a unique constraint the diff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # drops (ORA-02273: Oracle will not drop a constraint a foreign key rests on). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Returns the drops and the creates to put around the constraint operations; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # throws when the target has nothing for the key to point to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 118 | ▶ | sub _keys_over_gone_unique { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keys_over_gone_unique: called CC=21 SCAR=31.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 118 | my ($self, $gone) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 118 | ▶ | return ([], []) unless @$gone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | my ($src, $tgt) = ($self->source, $self->target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 8 | ▶ | my $set = sub { join ',', sort map { lc } @{ $_[0] // [] } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Condition50%1/2
$_[0] // []
MC/DC0%0/1
$_[0] // []
$_[0]
Truth table50%1/2
A
A= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | my %gone = map { ($_->table_name . "\x1f" . $set->($_->columns)) => 1 } @$gone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | my (@drop, @new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | ▶ | for my $table (sort keys %{ $src->{foreign_keys} // {} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$src->{"foreign_keys"} // {}
MC/DC100%1/1
$src->{"foreign_keys"} // {}
$src->{"foreign_keys"}
Truth table100%2/2
A
A= $src->{"foreign_keys"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | ▶ | next unless exists( ($tgt->{tables} // {})->{$table} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$tgt->{"tables"} // {}
MC/DC0%0/1
$tgt->{"tables"} // {}
$tgt->{"tables"}
Truth table50%1/2
A
A= $tgt->{"tables"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | my %want = map { DBIO::Oracle::Diff::ForeignKey::_signature($_) => $_ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | ▶ | @{ ($tgt->{foreign_keys} // {})->{$table} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
+($tgt->{"foreign_keys"} // {})->{$table} // []
$tgt->{"foreign_keys"} // {}
MC/DC0%0/1
+($tgt->{"foreign_keys"} // {})->{$table} // []
$tgt->{"foreign_keys"}
Truth table50%1/2
A
A= $tgt->{"foreign_keys"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | for my $fk (@{ $src->{foreign_keys}{$table} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | ▶ | my $stays = $want{ DBIO::Oracle::Diff::ForeignKey::_signature($fk) } or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | my $to = $fk->{to_table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | my $cols = $set->($fk->{to_columns}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | ▶ | next unless $gone{ $to . "\x1f" . $cols }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | my $held = grep { $set->($_->[1]) eq $cols } @{ ($tgt->{unique_constraints} // {})->{$to} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
+($tgt->{"unique_constraints"} // {})->{$to} // []
$tgt->{"unique_constraints"} // {}
MC/DC0%0/1
+($tgt->{"unique_constraints"} // {})->{$to} // []
$tgt->{"unique_constraints"}
Truth table50%1/2
A
A= $tgt->{"unique_constraints"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | ▶ | $held ||= $set->(($tgt->{primary_keys} // {})->{$to}) eq $cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$held ||= &$set(+($tgt->{"primary_keys"} // {})->{$to}) eq $cols
$tgt->{"primary_keys"} // {}
MC/DC100%2/2
$held ||= &$set(+($tgt->{"primary_keys"} // {})->{$to}) eq $cols
$held
&$set(+($tgt->{"primary_keys"} // {})->{$to}) eq $cols
MC/DC0%0/1
$tgt->{"primary_keys"} // {}
$tgt->{"primary_keys"}
Truth table100%3/3
A ||= B
A= $heldB= &$set(+($tgt->{"primary_keys"} // {})->{$to}) eq $cols
Truth table50%1/2
A
A= $tgt->{"primary_keys"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | ▶ | unless ($held) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | my @from = @{ $fk->{from_columns} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fk->{"from_columns"} // []
MC/DC0%0/1
$fk->{"from_columns"} // []
$fk->{"from_columns"}
Truth table50%1/2
A
A= $fk->{"from_columns"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | my @to = @{ $fk->{to_columns} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fk->{"to_columns"} // []
MC/DC0%0/1
$fk->{"to_columns"} // []
$fk->{"to_columns"}
Truth table50%1/2
A
A= $fk->{"to_columns"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | DBIO::Exception->throw(sprintf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | "DBIO::Oracle::Diff: the foreign key '%s' of table '%s' (column%s %s) stays, " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | . "but it points to column%s %s of table '%s', over which the target model has " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | . 'no unique constraint and no primary key (Oracle refuses to drop the constraint ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | . 'under a foreign key, ORA-02273)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ▶ | $stays->{constraint_name} // '', $table, (@from > 1 ? 's' : ''), join(', ', @from), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$stays->{"constraint_name"} // ""
MC/DC0%0/1
$stays->{"constraint_name"} // ""
$stays->{"constraint_name"}
Truth table50%1/2
A
A= $stays->{"constraint_name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | (@to > 1 ? 's' : ''), join(', ', @to), $to); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | push @drop, DBIO::Oracle::Diff::ForeignKey->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | action => 'drop', table_name => $table, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | constraint_name => $fk->{constraint_name}, fk_info => $fk, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | push @new, DBIO::Oracle::Diff::ForeignKey->create_op($table, $stays); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | return (\@drop, \@new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||