| 1 | ## -*- Mode: CPerl -*- | ||||||||||
| 2 | ## | ||||||||||
| 3 | ## File: DiaColloDB::Upgrade::v0_09_multimap.pm | ||||||||||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||
| 5 | ## Description: DiaColloDB utilities: auto-magic upgrade: v0.08.x -> v0.09.x: MultiMapFile format | ||||||||||
| 6 | |||||||||||
| 7 | package DiaColloDB::Upgrade::v0_09_multimap; | ||||||||||
| 8 | 1 | ▶ | use DiaColloDB::Upgrade::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use DiaColloDB::Compat::v0_08; | ||||||||
|
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 | ## + Upgrade: v0_09_multimap: v0.08.x -> v0.09.x : MultiMapFile format change | ||||||||||
| 16 | |||||||||||
| 17 | ## $version = $up->toversion() | ||||||||||
| 18 | ## + returns default target version; default just returns $DiaColloDB::VERSION | ||||||||||
| 19 | 0 | ▶ | sub toversion { | ||||||||
|
Subroutine
toversion: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 20 | 0 | return '0.09.000'; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | ## $bool = $up->upgrade() | ||||||||||
| 24 | ## + performs upgrade | ||||||||||
| 25 | 0 | ▶ | sub upgrade { | ||||||||
|
Subroutine
upgrade: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 26 | 0 | my $up = shift; | |||||||||
| 27 | |||||||||||
| 28 | ##-- backup | ||||||||||
| 29 | 0 | ▶ | $up->backup() or $up->logconfess("backup failed"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | |||||||||||
| 31 | ##-- open header | ||||||||||
| 32 | 0 | my $dbdir = $up->{dbdir}; | |||||||||
| 33 | 0 | my $hdr = $up->dbheader; | |||||||||
| 34 | |||||||||||
| 35 | ##-- convert by attribute | ||||||||||
| 36 | 0 | foreach my $attr (@{$hdr->{attrs}}) { | |||||||||
| 37 | 0 | my $base = "$dbdir/${attr}_2x"; | |||||||||
| 38 | 0 | ▶ | my $mmf = $DiaColloDB::MMCLASS->new(base=>$base, logCompat=>'off') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | or $up->logconfess("failed to open attribute multimap $base.*"); | ||||||||||
| 40 | |||||||||||
| 41 | ##-- sanity check(s) | ||||||||||
| 42 | 0 | $up->info("upgrading $base.*"); | |||||||||
| 43 | 0 | ▶ | $up->warn("multimap data in $base.* doesn't seem to be v0.08 format; trying to upgrade anyways") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | if (!$mmf->isa('DiaColloDB::Compat::v0_08::MultiMapFile')); | ||||||||||
| 45 | |||||||||||
| 46 | ##-- convert | ||||||||||
| 47 | my $tmp = $DiaColloDB::MMCLASS->new(flags=>'rw', pack_i=>$mmf->{pack_i}) | ||||||||||
| 48 | 0 | ▶ | or $up->logconfess("upgrade(): failed to create new DiaColloDB::MultiMapFile object for $base.*"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | ▶ | $tmp->fromArray($mmf->toArray) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | or $up->logconfess("upgrade(): failed to convert data for $base.*"); | ||||||||||
| 51 | 0 | $mmf->close(); | |||||||||
| 52 | 0 | ▶ | $tmp->save($base) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | or $up->logconfess("upgrade(): failed to save new data for $base.*"); | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | ##-- update header | ||||||||||
| 57 | 0 | return $up->updateHeader(); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | ##============================================================================== | ||||||||||
| 61 | ## Backup & Revert | ||||||||||
| 62 | |||||||||||
| 63 | ## $bool = $up->backup() | ||||||||||
| 64 | ## + perform backup any files we expect to change to $up->backupdir() | ||||||||||
| 65 | ## + call this from $up->upgrade() | ||||||||||
| 66 | 0 | ▶ | sub backup { | ||||||||
|
Subroutine
backup: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 67 | 0 | my $up = shift; | |||||||||
| 68 | 0 | ▶ | $up->SUPER::backup() or return undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | ▶ | return 1 if (!$up->{backup}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 0 | my $dbdir = $up->{dbdir}; | |||||||||
| 72 | 0 | my $hdr = $up->dbheader; | |||||||||
| 73 | 0 | my $backd = $up->backupdir; | |||||||||
| 74 | |||||||||||
| 75 | ##-- backup: by attribute | ||||||||||
| 76 | 0 | foreach my $base (map {"$dbdir/${_}_2x"} @{$hdr->{attrs}}) { | |||||||||
| 77 | 0 | $up->info("backing up $base.*"); | |||||||||
| 78 | 0 | ▶ | DiaColloDB::Utils::copyto_a([glob "$base.*"], $backd) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | or $up->logconfess("backup failed for $base.*: $!"); | ||||||||||
| 80 | } | ||||||||||
| 81 | 0 | return 1; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | ## @files = $up->revert_created() | ||||||||||
| 85 | ## + returns list of files created by this upgrade, for use with default rollback() implementation | ||||||||||
| 86 | 0 | ▶ | sub revert_created { | ||||||||
|
Subroutine
revert_created: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | 0 | return qw(); | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | ## @files = $up->revert_updated() | ||||||||||
| 91 | ## + returns list of files updated by this upgrade, for use with default rollback() implementation | ||||||||||
| 92 | 0 | ▶ | sub revert_updated { | ||||||||
|
Subroutine
revert_updated: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 93 | 0 | my $up = shift; | |||||||||
| 94 | 0 | my $hdr = $up->dbheader; | |||||||||
| 95 | |||||||||||
| 96 | my @mmfiles = map { | ||||||||||
| 97 | 0 | my $base="${_}_2x"; | |||||||||
| 98 | 0 | map {"$base.$_"} qw(hdr ma mb) | |||||||||
| 99 | 0 | } @{$hdr->{attrs}}; | |||||||||
| 100 | |||||||||||
| 101 | 0 | return (@mmfiles, 'header.json'); | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | ##============================================================================== | ||||||||||
| 106 | ## Footer | ||||||||||
| 107 | 1 | 1; ##-- be happy | |||||||||