migrator

package module
v0.0.0-...-5181f96 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2015 License: MPL-2.0 Imports: 8 Imported by: 0

README

Migrator

GoDoc

Opinionated database migration library for Go applications.

Supported databases
  • Postgres

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadFilenameFormat is returned if a migration file does not conform
	// with the expected name patter. Ex: 001_my-migration_up.sql
	ErrBadFilenameFormat = errors.New("bad-filename-format")
	// ErrInvalidDirection is returned if the direction of a migration is other
	// than 'up' or 'down'
	ErrInvalidDirection = errors.New("invalid-migration-direction")
	// ErrDBNotSupported is returned when trying to create a migrator instance
	// for an unsupported database.
	ErrDBNotSupported = errors.New("database-not-supported")
)
View Source
var (
	ErrCreatingTable        = errors.New("error-creating-migration-table")
	ErrMigrationFailed      = errors.New("migration-failed")
	ErrRegisteringMigration = errors.New("error-registering-migration")
	ErrGettingMigrations    = errors.New("error-getting-migrations")
	ErrRollbackFailed       = errors.New("error-rolling-back-migrations")
	ErrUpdatingMigration    = errors.New("error-updating-migration-metadata")
)

Functions

func NewPostgres

func NewPostgres(db *sql.DB) *postgres

Types

type AssetDirFunc

type AssetDirFunc func(path string) ([]string, error)

type AssetFunc

type AssetFunc func(path string) ([]byte, error)

type DBType

type DBType string
const (
	Postgres DBType = "postgres"
)

Supported databases.

type Migration

type Migration struct {
	ID        string
	Name      string
	Filename  string `db:"filename"`
	Up        string
	Down      string
	Status    string
	CreatedAt time.Time `db:"created_at"`
}

Migration represents an actual migration file.

type Migrator

type Migrator interface {
	// Init initializes migrations table in the given database.
	Init() error
	// Migrate runs a migration from an embedded asset. Go-bindata is the only
	// library supported.
	MigrateFromAsset(assetFunc AssetFunc, assetDirFunc AssetDirFunc) error
	// Rollback reverts the last migration.
	Rollback() error
	// RollbackN reverts the last N migrations.
	RollbackN(n uint) error
	// Migrations returns the list of migrations currently applied to the database.
	Migrations() ([]*Migration, error)
}

func NewMigrator

func NewMigrator(db *sql.DB, dbType DBType) (Migrator, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳