| 1 | ## -*- Mode: CPerl -*- | ||||||||||||||||||||||||||||
| 2 | ## | ||||||||||||||||||||||||||||
| 3 | ## File: DiaColloDB::Upgrade::v0_04_dlimits.pm | ||||||||||||||||||||||||||||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||||||||||||||||||
| 5 | ## Description: DiaColloDB utilities: auto-magic upgrade: v0.04: date-limits @$coldb{qw(xdmin xdmax)} | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package DiaColloDB::Upgrade::v0_04_dlimits; | ||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use DiaColloDB::Upgrade::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use DiaColloDB::Utils qw(:pack); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | our @ISA = qw(DiaColloDB::Upgrade::Base); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | ##============================================================================== | ||||||||||||||||||||||||||||
| 14 | ## API | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | ## $version = $up->toversion() | ||||||||||||||||||||||||||||
| 17 | ## + returns default target version; default just returns $DiaColloDB::VERSION | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub toversion { | ||||||||||||||||||||||||||
|
Subroutine
toversion: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | return '0.04.000'; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | ## $bool = $up->needed() | ||||||||||||||||||||||||||||
| 23 | ## + returns true iff local index in $dbdir needs upgrade | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub needed { | ||||||||||||||||||||||||||
|
Subroutine
needed: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 0 | my $up = shift; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | return !defined($up->{hdr}{xdmin}) || !defined($up->{hdr}{xdmax}); | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $up->{'hdr'}{'xdmin'} && defined $up->{'hdr'}{'xdmax'}
MC/DC0%0/2
defined $up->{'hdr'}{'xdmin'} && defined $up->{'hdr'}{'xdmax'}
defined $up->{'hdr'}{'xdmin'}
defined $up->{'hdr'}{'xdmax'}
Truth table0%0/3
A && B
A= defined $up->{'hdr'}{'xdmin'}B= defined $up->{'hdr'}{'xdmax'}
| |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | ## $bool = $up->upgrade() | ||||||||||||||||||||||||||||
| 30 | ## + performs upgrade | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub upgrade { | ||||||||||||||||||||||||||
|
Subroutine
upgrade: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 0 | my $up = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | ##-- backup | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $up->backup() or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | ##-- xdmin, xdmax: from xenum | ||||||||||||||||||||||||||||
| 38 | 0 | my $dbdir = $up->{dbdir}; | |||||||||||||||||||||||||||
| 39 | 0 | my $hdr = $up->dbheader; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $xenum = $DiaColloDB::XECLASS->new(base=>"$dbdir/xenum") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | or $up->logconfess("failed to open (tuple+date) enum $dbdir/xenum.*: $!"); | ||||||||||||||||||||||||||||
| 42 | 0 | my $pack_xdate = '@'.(packsize($hdr->{pack_id}) * scalar(@{$hdr->{attrs}})).$hdr->{pack_date}; | |||||||||||||||||||||||||||
| 43 | 0 | my ($dmin,$dmax) = (undef,undef); | |||||||||||||||||||||||||||
| 44 | 0 | my ($d); | |||||||||||||||||||||||||||
| 45 | 0 | foreach (@{$xenum->toArray}) { | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | next if (!$_ || !($d=unpack($pack_xdate,$_))); ##-- ignore null keys and dates | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ and $d = unpack($pack_xdate, $_)
MC/DC0%0/2
$_ and $d = unpack($pack_xdate, $_)
$_
$d = unpack($pack_xdate, $_)
Truth table0%0/3
A and B
A= $_B= $d = unpack($pack_xdate, $_)
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $dmin = $d if (!defined($dmin) || $d < $dmin); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $dmin or $d < $dmin
MC/DC0%0/2
not defined $dmin or $d < $dmin
not defined $dmin
$d < $dmin
Truth table0%0/3
not(A) or B
A= not defined $dminB= $d < $dmin
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $dmax = $d if (!defined($dmax) || $d > $dmax); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $dmax or $d > $dmax
MC/DC0%0/2
not defined $dmax or $d > $dmax
not defined $dmax
$d > $dmax
Truth table0%0/3
not(A) or B
A= not defined $dmaxB= $d > $dmax
| |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $dmin //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$dmin //= 0
MC/DC0%0/1
$dmin //= 0
$dmin
Truth table0%0/2
A
A= $dmin
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $dmax //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$dmax //= 0
MC/DC0%0/1
$dmax //= 0
$dmax
Truth table0%0/2
A
A= $dmax
| |||||||||||||||||||||||||||||
| 52 | 0 | $up->vlog('info', "extracted date-range \"xdmin\":$dmin, \"xdmax\":$dmax"); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | ##-- update header | ||||||||||||||||||||||||||||
| 55 | 0 | @$hdr{qw(xdmin xdmax)} = ($dmin,$dmax); | |||||||||||||||||||||||||||
| 56 | 0 | return $up->updateHeader(); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | ##============================================================================== | ||||||||||||||||||||||||||||
| 60 | ## Backups & Rollback | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | ## @files = $up->revert_created() | ||||||||||||||||||||||||||||
| 63 | ## + returns list of files created by this upgrade, for use with default rollback() implementation | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub revert_created { | ||||||||||||||||||||||||||
|
Subroutine
revert_created: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | return qw(); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | ## @files = $up->revert_updated() | ||||||||||||||||||||||||||||
| 69 | ## + returns list of files updated by this upgrade, for use with default rollback() implementation | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub revert_updated { | ||||||||||||||||||||||||||
|
Subroutine
revert_updated: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 0 | return qw(header.json); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | ##============================================================================== | ||||||||||||||||||||||||||||
| 76 | ## Footer | ||||||||||||||||||||||||||||
| 77 | 1 | 1; ##-- be happy | |||||||||||||||||||||||||||