migration

package
v0.0.0-...-1b7c243 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2017 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package migration provides a "micro-framework" for migration management: each migration is a simple function that returns an error. All migration functions are executed in the order they were registered.

Index

Constants

This section is empty.

Variables

View Source
var ErrCannotForceMandatory = errors.New("mandatory migrations can only run once")

ErrCannotForceMandatory is the error returned by Run when the force parameter is supplied without the name of a migration to run.

View Source
var ErrDuplicateMigration = errors.New("there's already a migration with this name")

ErrDuplicateMigration is the error returned by Register when the given name is already in use.

View Source
var ErrMigrationAlreadyExecuted = errors.New("migration already executed")

ErrMigrationAlreadyExecuted is the error returned by Run when the given name was previously executed and the force parameter was not supplied.

View Source
var ErrMigrationMandatory = errors.New("migration is mandatory")

ErrMigrationMandatory is the error returned by Run when the given name is not an optional migration. It should be executed calling Run.

View Source
var ErrMigrationNotFound = errors.New("migration not found")

ErrMigrationNotFound is the error returned by RunOptional when the given name is not a registered migration.

Functions

func List

func List() ([]migration, error)

func Register

func Register(name string, fn MigrateFunc) error

Register register a new migration for later execution with the Run functions.

func RegisterOptional

func RegisterOptional(name string, fn MigrateFunc) error

RegisterOptional register a new migration that will not run automatically when calling the Run funcition.

func Run

func Run(args RunArgs) error

Run runs all registered non optional migrations if no ".Name" is informed. Migrations are executed in the order that they were registered. If ".Name" is informed, an optional migration with the given name is executed.

Types

type MigrateFunc

type MigrateFunc func() error

MigrateFunc represents a migration function, that can be registered with the Register function. Migrations are later ran in the registration order, and this package keeps track of which migrate have ran already.

type RunArgs

type RunArgs struct {
	Name   string
	Writer io.Writer
	Dry    bool
	Force  bool
}

RunArgs is used by Run and RunOptional functions to modify how migrations are executed.

Jump to

Keyboard shortcuts

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