migrate

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Head = "head"
	None = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	// Version returns the current version of the schema in the backing datastore.
	// If the datastore is brand new, version should return the empty string without
	// an error.
	Version() (string, error)

	// WriteVersion records the newly migrated version to the backing datastore.
	WriteVersion(version, replaced string) error
}

Driver represents the common interface for reading and writing the revision data from a migrateable backing datastore.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is used to manage a self-contained set of migrations. Standard usage would be to instantiate one at the package level for a particular application and then statically register migrations to the single instantiation in init functions.

func NewManager

func NewManager() *Manager

NewManager creates a new empty instance of a migration manager.

func (*Manager) HeadRevision

func (m *Manager) HeadRevision() (string, error)

func (*Manager) Register

func (m *Manager) Register(version, replaces string, up interface{}) error

Register is used to associate a single migration with the migration engine. The up parameter should be a function that performs the actual upgrade logic and which takes a pointer to a concrete implementation of the Driver interface as its only parameters, which will be passed direcly from the Run method into the upgrade function. If not extra fields or data are required the function can alternatively take a Driver interface param.

func (*Manager) Run

func (m *Manager) Run(driver Driver, throughRevision string, dryRun RunType) error

Run will actually perform the necessary migrations to bring the backing datastore from its current revision to the specified revision.

type RunType

type RunType bool
var (
	DryRun  RunType = true
	LiveRun RunType = false
)

Jump to

Keyboard shortcuts

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