The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DiaColloDB::Upgrade::Base - DiaColloDB utilities: auto-magic upgrade: base class / API

SYNOPSIS

 ##========================================================================
 ## PRELIMINARIES
 
 use DiaColloDB::Upgrade::Base;
 
 ##========================================================================
 ## API
 
 $up      = $CLASS_OR_OBJECT->new($dbdir?, %opts);
 $pkg     = $CLASS_OR_OBJECT->label();
 $version = $up->toversion();
 $bool    = $up->needed();
 $bool    = $up->upgrade();
 
 ##========================================================================
 ## Backup & Revert
 
 $bool  = $up->backup();
 $dir   = $up->backupdir();
 
 $bool  = $up->revert();
 @files = $up->revert_created();
 @files = $up->revert_updated();
 
 ##========================================================================
 ## Utilities
 
 \%hdr   = $CLASS_OR_OBJECT->dbheader($dbdir?);
 \%uinfo = $up->uinfo($dbdir?,%info);
 $bool   = $up->updateHeader(\%extra_uinfo, \%extra_header_data);
 

DESCRIPTION

DiaColloDB::Upgrade::Base provides an API specification and common base class for automatic upgrade packages used by the dcdb-upgrade.perl script via the DiaColloDB::Upgrade package.

API

new
 $up = $CLASS_OR_OBJECT->new($dbdir?, %opts);

Create and return new upgrader-instance for the local DiaColloDB directory $dbdir. If $dbdir is specified, it is stored in $up->{dbdir} and its header is loaded to $up->{hdr}. Common %opts, %$up:

 backup   => $bool,   ##-- perform auto-backup? (default=1)
 keep     => $bool,   ##-- keep temporary files? (default=0)
 timestamp=> $stamp,  ##-- timestamp of this upgrade operation (default:DiaColloDB::Utils::timestamp(time))
label
 $pkg = $CLASS_OR_OBJECT->label();

Returns upgrade package name.

toversion
 $version = $CLASS_OR_OBJECT->toversion();

Returns default target version; default just returns $DiaColloDB::VERSION. By convention, auto-applied upgrades use a target version with an all-zero final version component, e.g. 0.09.000 or 0.10.000.

needed
 $bool = $up->needed();

Returns true iff the upgrade $up needs to be applied to the local DiaColloDB index in $dbdir. Default implementation returns true iff $up->dbheader($dbdir)->{version} < $up->toversion(), using the version package to parse and compare version strings.

upgrade
 $bool = $up->upgrade();

Performs upgrade in-place on the local DiaColloDB index in $up->{dbdir}, returns true on success.

Backup & Revert

backup
 $bool = $up->backup();

Backup any files we expect to change during upgrade() to $up->backupdir(). Subclasses should call this from their upgrade() method. Default implementation just backs up "$dbdir/header.json", emitting a warning if $up->{backup} is false.

backupdir
 $dir = $up->backupdir();

Returns name of a backup directory for this upgrade. Default generates a reasonably unique directory name by concatenating the upgrader's label() suffix with the "wordlike" characters of $up->{timestamp}. For revert() to work, this directory name should be unique given $dbdir and the HASH-ref returned by the uinfo() method.

revert
 $bool = $up->revert();

Reverts a previous upgrade by $up on the local DB directory $up->{dbdir}. Default implementation deletes files returned by $up->revert_created() and copies files returned by $up->revert_updated() from $up->backupdir().

revert_created
 @files = $up->revert_created();

Returns list of files created by this upgrade, for use with default revert() implementation

revert_updated
 @files = $up->revert_updated();

Returns list of files updated by this upgrade, for use with default revert() implementation.

Utilities

dbheader
 \%hdr = $CLASS_OR_OBJECT->dbheader($dbdir?);

Reads, parses, and returns the header information $dbdir/header.json for the local DiaColloDB index in $dbdir. Wraps DiaColloDB::Utils::loadJsonFile(). Default implementation uses cached $CLASS_OR_OBJECT->{hdr} if available.

uinfo
 \%uinfo = $up->uinfo($dbdir?,%info);

Returns a default upgrade-info %uinfo structure for this upgrade, conventions:

 version_from => $vfrom,    ##-- source version (default='unknown')
 version_to   => $vto,      ##-- target version (default=$CLASS_OR_OBJECT->_toversion)
 timestamp    => $time,     ##-- timestamp (default=DiaColloDB::Utils::timestamp(time))
 by           => $who,      ##-- upgrade class or DiaColloDB::Upgrade:: suffix
 #...         => ...,       ##-- additional data from %info
updateHeader
 $bool = $up->updateHeader(\%extra_uinfo, \%extra_header_data);

Updates DiaColloDB header "$up->{dbdir}/header.json" by prepending the upgrade-info structure returned by $up->uinfo($coldb,%extra_uinfo) onto the headers "upgraded" array and setting header "version" to $uinfo->{version_to} if that value is true. Subclasses may call this from their upgrade() method.

AUTHOR

Bryan Jurish <moocow@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2016 by Bryan Jurish

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.

SEE ALSO

dcdb-upgrade.perl(1), DiaColloDB::Upgrade(3pm), DiaColloDB(3pm), perl(1), ...