migrate

package
v0.0.0-...-e49eac2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2015 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MIGRATION_TABLE = "migrations"

Variables

This section is empty.

Functions

func Main

func Main(defn *Definitions, m Migrator)

Main should be called from user-level code's main() function to process the arguments and run migrations provided. It reads the arguments provided on the command line.

Types

type Definitions

type Definitions struct {
	Up   map[int]MigrationFunc
	Down map[int]MigrationFunc
}

Definitions is a convenient way to hold the up and down migrations in a struct.

type MigrationFunc

type MigrationFunc func(*sql.Tx) error

This is the function type that the Migrator operates on. The implementors of this type do not need to start or stop transactions, just use the transaction provided and error if something goes wrong.

type Migrator

type Migrator interface {
	DestroyMigrationRecords() error
	Close() error
	CurrentMigrationNumber() (int, error)
	Up(migrations map[int]MigrationFunc) (int, error)
	Down(map[int]MigrationFunc) (int, error)
	UpTo(int, map[int]MigrationFunc) (int, error)
	DownTo(int, map[int]MigrationFunc) (int, error)
	DumpHistory(io.Writer) error
}

Migrator is a type meant to represent the small table that is kept about the migrations performend and the ability to run up/down migrations. Note that this exposes the lower level sql.Tx interface to callers because it is likely that migrations are not portable between databases (there are things you want to be able to do that are DB specific). This is in contrast to the use of Qbs elsewhere as the _use_ of the database should be db-implementation independent.

func NewPostgresMigrator

func NewPostgresMigrator(url string) (Migrator, error)

NewPostgresMigrator returns a new migrator capable of performing a sequence of migrations. Note that this typically will fail (returning the error when the DB connection cannot be established). There is no connection pooling or other optimizations done in Migrator because it is designed to be used primarily in one-off migration situations.

Jump to

Keyboard shortcuts

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