| 1 | package DBIO::Informix::Diff::Index; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Diff operations for Informix indexes | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 24 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 24 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 24 | ▶ | use DBIO::Diff::Compare qw(changed_index_fields); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 24 | ▶ | use DBIO::Informix::Util qw(_quote_ident); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 24 | __PACKAGE__->mk_diff_accessors(qw(index_name table_name index_info replaced)); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 55 | ▶ | sub diff { | ||||||||||||||||||||||||||
|
Subroutine
diff: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 55 | my ($class, $source, $target) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 55 | my @ops; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 55 | for my $table (sort keys %$target) { | |||||||||||||||||||||||||||
| 24 | 7 | ▶ | for my $name (sort keys %{ $target->{$table} // {} }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$target->{$table} // {}
MC/DC0%0/1
$target->{$table} // {}
$target->{$table}
Truth table50%1/2
A
A= $target->{$table}
| |||||||||||||||||||||||||||||
| 25 | 7 | my $tgt_idx = $target->{$table}{$name}; | |||||||||||||||||||||||||||
| 26 | 7 | ▶ | my $src_idx = $source->{$table} && $source->{$table}{$name}; | ||||||||||||||||||||||||||
|
Condition100%3/3
$source->{$table} && $source->{$table}{$name}
MC/DC100%2/2
$source->{$table} && $source->{$table}{$name}
$source->{$table}
$source->{$table}{$name}
Truth table100%3/3
A && B
A= $source->{$table}B= $source->{$table}{$name}
| |||||||||||||||||||||||||||||
| 27 | 7 | ▶ | if (!$src_idx) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 28 | 4 | push @ops, $class->new( | |||||||||||||||||||||||||||
| 29 | action => 'create', | ||||||||||||||||||||||||||||
| 30 | index_name => $name, | ||||||||||||||||||||||||||||
| 31 | table_name => $table, | ||||||||||||||||||||||||||||
| 32 | index_info => $tgt_idx, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | elsif (changed_index_fields(_compare_view($src_idx), _compare_view($tgt_idx))) { | ||||||||||||||||||||||||||||
| 36 | # Definition changed -- Informix has no ALTER INDEX, emit drop+create | ||||||||||||||||||||||||||||
| 37 | 3 | push @ops, $class->new( | |||||||||||||||||||||||||||
| 38 | action => 'drop', | ||||||||||||||||||||||||||||
| 39 | index_name => $name, | ||||||||||||||||||||||||||||
| 40 | table_name => $table, | ||||||||||||||||||||||||||||
| 41 | index_info => $src_idx, | ||||||||||||||||||||||||||||
| 42 | replaced => 1, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | 3 | push @ops, $class->new( | |||||||||||||||||||||||||||
| 45 | action => 'create', | ||||||||||||||||||||||||||||
| 46 | index_name => $name, | ||||||||||||||||||||||||||||
| 47 | table_name => $table, | ||||||||||||||||||||||||||||
| 48 | index_info => $tgt_idx, | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 55 | for my $table (sort keys %$source) { | |||||||||||||||||||||||||||
| 55 | 6 | ▶ | for my $name (sort keys %{ $source->{$table} // {} }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$source->{$table} // {}
MC/DC0%0/1
$source->{$table} // {}
$source->{$table}
Truth table50%1/2
A
A= $source->{$table}
| |||||||||||||||||||||||||||||
| 56 | 7 | ▶ | next if $target->{$table} && $target->{$table}{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$target->{$table} and $target->{$table}{$name}
MC/DC100%2/2
$target->{$table} and $target->{$table}{$name}
$target->{$table}
$target->{$table}{$name}
Truth table100%3/3
A and B
A= $target->{$table}B= $target->{$table}{$name}
| |||||||||||||||||||||||||||||
| 57 | push @ops, $class->new( | ||||||||||||||||||||||||||||
| 58 | action => 'drop', | ||||||||||||||||||||||||||||
| 59 | index_name => $name, | ||||||||||||||||||||||||||||
| 60 | table_name => $table, | ||||||||||||||||||||||||||||
| 61 | 4 | index_info => $source->{$table}{$name}, | |||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 55 | return @ops; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Informix introspected indexes carry C<unique>; L</changed_index_fields> expects | ||||||||||||||||||||||||||||
| 70 | # the canonical C<is_unique>. The C<columns> field is already in canonical | ||||||||||||||||||||||||||||
| 71 | # shape. Build a comparison-only view, leave the original index_info alone | ||||||||||||||||||||||||||||
| 72 | # for C<as_sql>. | ||||||||||||||||||||||||||||
| 73 | 6 | ▶ | sub _compare_view { | ||||||||||||||||||||||||||
|
Subroutine
_compare_view: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 74 | 6 | my ($idx) = @_; | |||||||||||||||||||||||||||
| 75 | return { | ||||||||||||||||||||||||||||
| 76 | is_unique => $idx->{unique} ? 1 : 0, | ||||||||||||||||||||||||||||
| 77 | columns => $idx->{columns}, | ||||||||||||||||||||||||||||
| 78 | 6 | ▶ | }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 10 | ▶ | sub as_sql { | ||||||||||||||||||||||||||
|
Subroutine
as_sql: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 10 | my $idx_name = _quote_ident($self->index_name); | |||||||||||||||||||||||||||
| 86 | 10 | my $tab_name = _quote_ident($self->table_name); | |||||||||||||||||||||||||||
| 87 | 10 | my $cols = join(', ', map { _quote_ident($_) } @{$self->index_info->{columns}}); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 10 | ▶ | if ($self->action eq 'drop') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 4 | return sprintf 'DROP INDEX %s;', $idx_name; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 6 | ▶ | my $unique = $self->index_info->{unique} ? 'UNIQUE ' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 6 | return sprintf 'CREATE %sINDEX %s ON %s (%s);', $unique, $idx_name, $tab_name, $cols; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | sub summary { | ||||||||||||||||||||||||||
|
Subroutine
summary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 100 | 1 | return sprintf '%s index: %s on %s', | |||||||||||||||||||||||||||
| 101 | $self->summary_prefix, $self->index_name, $self->table_name; | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 24 | 1; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||