migration

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2019 License: ISC Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 " +
		"supported")
)

Functions

func DisableLog

func DisableLog()

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

func GetLatestVersion

func GetLatestVersion(versions []Version) uint32

GetLatestVersion returns the latest version available from the given slice.

func Upgrade

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

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.

Types

type Manager

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

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL