bchwallet: github.com/gcash/bchwallet/walletdb/migration Index | Files

package migration

import "github.com/gcash/bchwallet/walletdb/migration"


Package Files

log.go manager.go


var (
    // ErrReversion is an error returned when an attempt to revert to a
    // previous version is detected. This is done to provide safety to users
    // as some upgrades may not be backwards-compatible.
    ErrReversion = errors.New("reverting to a previous version is not " +

func DisableLog Uses

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func GetLatestVersion Uses

func GetLatestVersion(versions []Version) uint32

GetLatestVersion returns the latest version available from the given slice.

func Upgrade Uses

func Upgrade(mgrs ...Manager) error

Upgrade attempts to upgrade a group of services exposed through the Manager interface. Each service will go through its available versions and determine whether it needs to apply any.

NOTE: In order to guarantee fault-tolerance, each service upgrade should happen within the same database transaction.

func UseLogger Uses

func UseLogger(logger bchlog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

type Manager Uses

type Manager interface {
    // Name returns the name of the service we'll be attempting to upgrade.
    Name() string

    // Namespace returns the top-level bucket of the service.
    Namespace() walletdb.ReadWriteBucket

    // CurrentVersion returns the current version of the service's database.
    CurrentVersion(walletdb.ReadBucket) (uint32, error)

    // SetVersion sets the version of the service's database.
    SetVersion(walletdb.ReadWriteBucket, uint32) error

    // Versions returns all of the available database versions of the
    // service.
    Versions() []Version

Manager is an interface that exposes the necessary methods needed in order to migrate/upgrade a service. Each service (i.e., an implementation of this interface) can then use the Upgrade function to perform any required database migrations.

type Version Uses

type Version struct {
    // Number represents the number of this version.
    Number uint32

    // Migration represents a migration function that modifies the database
    // state. Care must be taken so that consequent migrations build off of
    // the previous one in order to ensure the consistency of the database.
    Migration func(walletdb.ReadWriteBucket) error

Version denotes the version number of the database. A migration can be used to bring a previous version of the database to a later one.

func VersionsToApply Uses

func VersionsToApply(currentVersion uint32, versions []Version) []Version

VersionsToApply determines which versions should be applied as migrations based on the current version.

Package migration imports 4 packages (graph) and is imported by 6 packages. Updated 2018-12-06. Refresh now. Tools for package owners.