| 1 | package DBIO::DuckDB::Diff::Index; | ||||||||||||
| 2 | # ABSTRACT: Diff operations for DuckDB indexes | ||||||||||||
| 3 | |||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 8 | our $VERSION = '0.900007'; | |||||||||||
| 8 | |||||||||||||
| 9 | 8 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 8 | ▶ | use DBIO::DuckDB::DDL::Emit qw(quote_ident); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 8 | ▶ | use DBIO::DuckDB::DDL::Emit qw(create_index); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 8 | ▶ | use DBIO::Diff::Compare qw(changed_index_fields); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 8 | __PACKAGE__->mk_diff_accessors(qw/table_name index_name index_info/); | |||||||||||
| 16 | |||||||||||||
| 17 | |||||||||||||
| 18 | |||||||||||||
| 19 | 5 | ▶ | sub diff { | ||||||||||
|
Subroutine
diff: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||
| 20 | 5 | my ($class, $source, $target, $source_tables, $target_tables) = @_; | |||||||||||
| 21 | |||||||||||||
| 22 | # Tables present in the source model but absent from the target are being | ||||||||||||
| 23 | # dropped in this same pass. DuckDB's DROP TABLE removes the table's own | ||||||||||||
| 24 | # indexes, so a later standalone DROP INDEX for one of them must be | ||||||||||||
| 25 | # suppressed (karr k8). | ||||||||||||
| 26 | 5 | ▶ | $source_tables //= {}; | ||||||||||
|
Condition100%2/2
$source_tables //= {}
MC/DC100%1/1
$source_tables //= {}
$source_tables
Truth table100%2/2
A
A= $source_tables
| |||||||||||||
| 27 | 5 | ▶ | $target_tables //= {}; | ||||||||||
|
Condition100%2/2
$target_tables //= {}
MC/DC100%1/1
$target_tables //= {}
$target_tables
Truth table100%2/2
A
A= $target_tables
| |||||||||||||
| 28 | 2 | my %dropped_table = map { $_ => 1 } | |||||||||||
| 29 | 5 | grep { !exists $target_tables->{$_} } keys %$source_tables; | |||||||||||
| 30 | |||||||||||||
| 31 | return $class->diff_nested($source, $target, | ||||||||||||
| 32 | scope => 'all', | ||||||||||||
| 33 | 0 | ▶ | changed_when => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 34 | 0 | my ($old, $new) = @_; | |||||||||||
| 35 | 0 | scalar changed_index_fields($old, $new); | |||||||||||
| 36 | }, | ||||||||||||
| 37 | 0 | ▶ | on_new => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 38 | 0 | my ($table_name, $name, $tgt) = @_; | |||||||||||
| 39 | 0 | $class->new( | |||||||||||
| 40 | action => 'create', | ||||||||||||
| 41 | table_name => $table_name, | ||||||||||||
| 42 | index_name => $name, | ||||||||||||
| 43 | index_info => $tgt, | ||||||||||||
| 44 | ); | ||||||||||||
| 45 | }, | ||||||||||||
| 46 | 0 | ▶ | on_changed => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 47 | 0 | my ($table_name, $name, $old, $new) = @_; | |||||||||||
| 48 | return ( | ||||||||||||
| 49 | 0 | $class->new( | |||||||||||
| 50 | action => 'drop', table_name => $table_name, | ||||||||||||
| 51 | index_name => $name, index_info => $old, | ||||||||||||
| 52 | ), | ||||||||||||
| 53 | $class->new( | ||||||||||||
| 54 | action => 'create', table_name => $table_name, | ||||||||||||
| 55 | index_name => $name, index_info => $new, | ||||||||||||
| 56 | ), | ||||||||||||
| 57 | ); | ||||||||||||
| 58 | }, | ||||||||||||
| 59 | 5 | ▶ | on_gone => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 60 | 5 | my ($table_name, $name, $old) = @_; | |||||||||||
| 61 | # Skip when the owning table is itself being dropped this pass; DuckDB's | ||||||||||||
| 62 | # DROP TABLE already removes this index (karr k8). | ||||||||||||
| 63 | 5 | ▶ | return () if $dropped_table{$table_name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | 3 | $class->new( | |||||||||||
| 65 | action => 'drop', | ||||||||||||
| 66 | table_name => $table_name, | ||||||||||||
| 67 | index_name => $name, | ||||||||||||
| 68 | index_info => $old, | ||||||||||||
| 69 | ); | ||||||||||||
| 70 | }, | ||||||||||||
| 71 | 5 | ); | |||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | |||||||||||||
| 75 | 2 | ▶ | sub as_sql { | ||||||||||
|
Subroutine
as_sql: called CC=5 SCAR=27.0
Pod
documented
| |||||||||||||
| 76 | 2 | my ($self) = @_; | |||||||||||
| 77 | |||||||||||||
| 78 | 2 | ▶ | if ($self->action eq 'create') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | 0 | ▶ | if (my $sql = $self->index_info->{sql}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | 0 | ▶ | $sql .= ';' unless $sql =~ /;\s*$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | 0 | return $sql; | |||||||||||
| 82 | } | ||||||||||||
| 83 | return create_index( | ||||||||||||
| 84 | name => $self->index_name, | ||||||||||||
| 85 | table => $self->table_name, | ||||||||||||
| 86 | columns => $self->index_info->{columns} // [], | ||||||||||||
| 87 | unique => $self->index_info->{is_unique}, | ||||||||||||
| 88 | 0 | ▶ | ); | ||||||||||
|
Condition0%0/2
$self->index_info->{"columns"} // []
MC/DC0%0/1
$self->index_info->{"columns"} // []
$self->index_info->{"columns"}
Truth table0%0/2
A
A= $self->index_info->{"columns"}
| |||||||||||||
| 89 | } | ||||||||||||
| 90 | 2 | return sprintf 'DROP INDEX %s;', quote_ident($self->index_name); | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | |||||||||||||
| 94 | 0 | ▶ | sub summary { | ||||||||||
|
Subroutine
summary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 95 | 0 | my ($self) = @_; | |||||||||||
| 96 | 0 | return sprintf ' %sindex: %s on %s', | |||||||||||
| 97 | $self->summary_prefix, $self->index_name, $self->table_name; | ||||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | 8 | 1; | |||||||||||
| 101 | |||||||||||||
| 102 | __END__ | ||||||||||||