| 1 | package DBIO::Oracle::Diff::Index; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Diff operations for Oracle indexes | ||||||||||||||||||||||||||||
| 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::Op'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 30 | ▶ | use DBIO::Oracle::Identifier (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 30 | ▶ | use DBIO::Diff::Compare qw(changed_index_fields); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 30 | __PACKAGE__->mk_diff_accessors(qw(index_name table_name index_info)); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 46 | ▶ | sub diff { | ||||||||||||||||||||||||||
|
Subroutine
diff: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 46 | my ($class, $source, $target, $source_tables, $target_tables) = @_; | |||||||||||||||||||||||||||
| 20 | 46 | ▶ | $source ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$source ||= {}
MC/DC0%0/1
$source ||= {}
$source
Truth table50%1/2
A
A= $source
| |||||||||||||||||||||||||||||
| 21 | 46 | ▶ | $target ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$target ||= {}
MC/DC0%0/1
$target ||= {}
$target
Truth table50%1/2
A
A= $target
| |||||||||||||||||||||||||||||
| 22 | 46 | ▶ | $source_tables ||= $source; | ||||||||||||||||||||||||||
|
Condition66%2/3
$source_tables ||= $source
MC/DC0%0/2
$source_tables ||= $source
$source_tables
$source
Truth table66%2/3
A ||= B
A= $source_tablesB= $source
| |||||||||||||||||||||||||||||
| 23 | 46 | ▶ | $target_tables ||= $target; | ||||||||||||||||||||||||||
|
Condition66%2/3
$target_tables ||= $target
MC/DC0%0/2
$target_tables ||= $target
$target_tables
$target
Truth table66%2/3
A ||= B
A= $target_tablesB= $target
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 9 | ▶ | my $new_index = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 9 | my ($tbl, $idx_name, $idx) = @_; | |||||||||||||||||||||||||||
| 27 | 9 | return $class->new( | |||||||||||||||||||||||||||
| 28 | action => 'create', | ||||||||||||||||||||||||||||
| 29 | index_name => $idx_name, | ||||||||||||||||||||||||||||
| 30 | table_name => $tbl, | ||||||||||||||||||||||||||||
| 31 | index_info => $idx, | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | 46 | }; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | my @ops = $class->diff_nested( | ||||||||||||||||||||||||||||
| 36 | $source, $target, | ||||||||||||||||||||||||||||
| 37 | scope => 'both', | ||||||||||||||||||||||||||||
| 38 | source_tables => $source_tables, | ||||||||||||||||||||||||||||
| 39 | target_tables => $target_tables, | ||||||||||||||||||||||||||||
| 40 | 10 | ▶ | changed_when => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 10 | my ($old, $new) = @_; | |||||||||||||||||||||||||||
| 42 | 10 | return scalar changed_index_fields($old, $new); | |||||||||||||||||||||||||||
| 43 | }, | ||||||||||||||||||||||||||||
| 44 | on_new => $new_index, | ||||||||||||||||||||||||||||
| 45 | 2 | ▶ | on_changed => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 2 | my ($tbl, $idx_name, $old, $new) = @_; | |||||||||||||||||||||||||||
| 47 | return ( | ||||||||||||||||||||||||||||
| 48 | 2 | $class->new( | |||||||||||||||||||||||||||
| 49 | action => 'drop', | ||||||||||||||||||||||||||||
| 50 | index_name => $idx_name, | ||||||||||||||||||||||||||||
| 51 | table_name => $tbl, | ||||||||||||||||||||||||||||
| 52 | index_info => $old, | ||||||||||||||||||||||||||||
| 53 | ), | ||||||||||||||||||||||||||||
| 54 | $class->new( | ||||||||||||||||||||||||||||
| 55 | action => 'create', | ||||||||||||||||||||||||||||
| 56 | index_name => $idx_name, | ||||||||||||||||||||||||||||
| 57 | table_name => $tbl, | ||||||||||||||||||||||||||||
| 58 | index_info => $new, | ||||||||||||||||||||||||||||
| 59 | ), | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||
| 62 | 6 | ▶ | on_gone => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 6 | my ($tbl, $idx_name, $idx) = @_; | |||||||||||||||||||||||||||
| 64 | 6 | $class->new( | |||||||||||||||||||||||||||
| 65 | action => 'drop', | ||||||||||||||||||||||||||||
| 66 | index_name => $idx_name, | ||||||||||||||||||||||||||||
| 67 | table_name => $tbl, | ||||||||||||||||||||||||||||
| 68 | index_info => $idx, | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||
| 71 | 46 | ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # The tables only the target has: all of their indexes are new. | ||||||||||||||||||||||||||||
| 74 | 46 | for my $tbl (sort keys %$target) { | |||||||||||||||||||||||||||
| 75 | 34 | ▶ | next if exists $source_tables->{$tbl} || !exists $target_tables->{$tbl}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $source_tables->{$tbl} or not exists $target_tables->{$tbl}
MC/DC50%1/2
exists $source_tables->{$tbl} or not exists $target_tables->{$tbl}
exists $source_tables->{$tbl}
not exists $target_tables->{$tbl}
Truth table66%2/3
A or not(B)
A= exists $source_tables->{$tbl}B= not exists $target_tables->{$tbl}
| |||||||||||||||||||||||||||||
| 76 | 8 | my $indexes = $target->{$tbl}; | |||||||||||||||||||||||||||
| 77 | 8 | push @ops, map { $new_index->($tbl, $_, $indexes->{$_}) } sort keys %$indexes; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 46 | return @ops; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 23 | ▶ | sub as_sql { | ||||||||||||||||||||||||||
|
Subroutine
as_sql: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 23 | my ($self) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 23 | my $idx = DBIO::Oracle::Identifier::quote_in($self->table_name, $self->index_name); | |||||||||||||||||||||||||||
| 88 | 23 | my $tbl = DBIO::Oracle::Identifier::quote_table($self->table_name); | |||||||||||||||||||||||||||
| 89 | 23 | my $info = $self->index_info; | |||||||||||||||||||||||||||
| 90 | 23 | ▶ | my $cols = join(', ', map { DBIO::Oracle::Identifier::quote($_) } @{ $info->{columns} // [] }); | ||||||||||||||||||||||||||
|
Condition50%1/2
$info->{"columns"} // []
MC/DC0%0/1
$info->{"columns"} // []
$info->{"columns"}
Truth table50%1/2
A
A= $info->{"columns"}
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 23 | ▶ | if ($self->action eq 'create') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 18 | ▶ | my $unique = $info->{is_unique} ? 'UNIQUE ' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 18 | return sprintf 'CREATE %sINDEX %s ON %s (%s);', | |||||||||||||||||||||||||||
| 95 | $unique, $idx, $tbl, $cols; | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 5 | ▶ | if ($self->action eq 'drop') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 5 | return sprintf 'DROP INDEX %s;', $idx; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 6 | ▶ | sub summary { | ||||||||||||||||||||||||||
|
Subroutine
summary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 106 | 6 | return sprintf ' %sindex: %s on %s', | |||||||||||||||||||||||||||
| 107 | $self->summary_prefix, $self->index_name, $self->table_name; | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 30 | 1; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||