blib/lib/DBIO/DuckDB/Diff/Rebuild.pm

filter: Statementstmt 47.7% 21 / 44 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 54.5% 6 / 11 Podpod 100% 5 / 5 totaltotal 39.0% 32 / 82 CC 9 SCAR 19.8
CC
9
Cov
34%
as_sql
12.0
lossy_columns
12.0
summary
12.0
CRAP 7.3
« blib/lib/DBIO/DuckDB/Test.pm ↑ Summary blib/lib/DBIO/DuckDB/Diff/Index.pm »
1 package DBIO::DuckDB::Diff::Rebuild;
2 # ABSTRACT: Rebuild a DuckDB table for what ALTER TABLE cannot do
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::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use DBIO::DuckDB::DDL::Emit qw(quote_ident quote_table split_table);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use DBIO::DuckDB::Diff::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 __PACKAGE__->mk_diff_accessors(qw/
16 table_name columns foreign_keys unique_constraints copy_columns reasons column_ops
17 /);
18  
19  
20  
21 0 ▶sub tmp_name {
Subroutine tmp_name: not called CC=2 SCAR=17.9
Pod documented
22 0 my ($self) = @_;
23 0 my ($schema, $table) = split_table($self->table_name);
24 0 ▶ return (defined $schema ? "$schema." : '') . $table . '__dbio_rebuild';
Branch: 1 branch
BranchTrueFalseTotal
defined $schema ? : 0 0 0
25 }
26  
27  
28 0 ▶sub as_sql {
Subroutine as_sql: not called CC=3 SCAR=24.8
Pod documented
29 0 my ($self) = @_;
30 0 ▶ my @copy = @{ $self->copy_columns || [] };
Condition0%0/2
$self->copy_columns || []
l!l
00
MC/DC0%0/1
$self->copy_columns || []
$self->copy_columns
Truth table0%0/2
A
A= $self->copy_columns
Aresult
11
00
31 0 ▶ DBIO::Exception->throw(sprintf
Branch: 1 branch
BranchTrueFalseTotal
unless @copy 0 0 0
32 "Cannot rebuild table '%s': the old and the new table have no column in common, no row could be carried over",
33 $self->table_name) unless @copy;
34  
35 0 my $create = DBIO::DuckDB::Diff::Table->new(
36 action => 'create',
37 table_name => $self->tmp_name,
38 columns => $self->columns,
39 foreign_keys => $self->foreign_keys,
40 unique_constraints => $self->unique_constraints,
41 )->as_sql;
42  
43 0 my $list = join ', ', map { quote_ident($_) } @copy;
44 0 my ($schema, $table) = split_table($self->table_name);
45 0 return join "\n",
46 $create,
47 sprintf('INSERT INTO %s (%s) SELECT %s FROM %s;',
48 quote_table($self->tmp_name), $list, $list, quote_table($self->table_name)),
49 sprintf('DROP TABLE %s;', quote_table($self->table_name)),
50 sprintf('ALTER TABLE %s RENAME TO %s;', quote_table($self->tmp_name), quote_ident($table));
51 }
52  
53  
54 0 ▶sub lossy_columns {
Subroutine lossy_columns: not called CC=3 SCAR=24.8
Pod documented
55 0 my ($self) = @_;
56 0 return map { $_->column_name }
57 0 ▶ grep { $_->action eq 'drop' || $_->lossy } @{ $self->column_ops || [] };
Condition0%0/5
$_->action eq 'drop' || $_->lossy
l!l&&r!l&&!r
000
$self->column_ops || []
l!l
00
MC/DC0%0/2
$_->action eq 'drop' || $_->lossy
$_->action eq 'drop' $_->lossy
MC/DC0%0/1
$self->column_ops || []
$self->column_ops
Truth table0%0/3
A || B
A= $_->action eq 'drop'B= $_->lossy
ABresult
1X1
011
000
Truth table0%0/2
A
A= $self->column_ops
Aresult
11
00
58 }
59  
60  
61 0 ▶sub lossy { scalar(my @c = $_[0]->lossy_columns) ? 1 : 0 }
Subroutine lossy: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
scalar(my(@c) = $_[0]->lossy_columns) ? : 0 0 0
62  
63  
64 0 ▶sub summary {
Subroutine summary: not called CC=3 SCAR=24.8
Pod documented
65 0 my ($self) = @_;
66 0 my @lossy = map { $self->table_name . ".$_" } $self->lossy_columns;
67 return sprintf '%s rebuild table: %s (%s)%s', $self->summary_prefix,
68 0 ▶ $self->table_name, join('; ', @{ $self->reasons || [] }),
Branch: 1 branch
BranchTrueFalseTotal
@lossy ? : 0 0 0
Condition0%0/2
$self->reasons || []
l!l
00
MC/DC0%0/1
$self->reasons || []
$self->reasons
Truth table0%0/2
A
A= $self->reasons
Aresult
11
00
69 (@lossy ? ' drops or may alter: ' . join(', ', @lossy) : '');
70 }
71  
72 8 1;
73  
74 __END__
« blib/lib/DBIO/DuckDB/Test.pm ↑ Summary blib/lib/DBIO/DuckDB/Diff/Index.pm »