migrate

package
v0.0.0-...-ff14caf Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoFwMigration = errors.Errorf("no sql in forward migration step")

Functions

func FindMigrationsEx

func FindMigrationsEx(path string, fs MigratorFS) ([]string, error)

Types

type BadVersionError

type BadVersionError string

func (BadVersionError) Error

func (e BadVersionError) Error() string

type IrreversibleMigrationError

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

func (IrreversibleMigrationError) Error

type Migration

type Migration struct {
	Sequence int32
	Name     string
	UpSQL    string
	DownSQL  string
}

type Migrator

type Migrator struct {
	Migrations []*Migration
	OnStart    func(int32, string, string, string) // OnStart is called when a migration is run with the sequence, name, direction, and SQL
	Data       map[string]interface{}              // Data available to use in migrations
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(conn *pgx.Conn, versionTable string) (m *Migrator, err error)

func NewMigratorEx

func NewMigratorEx(conn *pgx.Conn, versionTable string, opts *MigratorOptions) (m *Migrator, err error)

func (*Migrator) AppendMigration

func (m *Migrator) AppendMigration(name, upSQL, downSQL string)

func (*Migrator) GetCurrentVersion

func (m *Migrator) GetCurrentVersion() (v int32, err error)

func (*Migrator) LoadMigrations

func (m *Migrator) LoadMigrations(path string) error

func (*Migrator) Migrate

func (m *Migrator) Migrate(onCommitFailed func(err error) (retry bool)) error

Migrate runs pending migrations It calls m.OnStart when it begins a migration

func (*Migrator) MigrateTo

func (m *Migrator) MigrateTo(targetVersion int32, onCommitFailed func(err error) (retry bool)) (err error)

MigrateTo migrates to targetVersion

type MigratorFS

type MigratorFS interface {
	ReadDir(dirname string) ([]os.FileInfo, error)
	ReadFile(filename string) ([]byte, error)
	Glob(pattern string) (matches []string, err error)
}

type MigratorOptions

type MigratorOptions struct {
	// MigratorFS is the interface used for collecting the migrations.
	MigratorFS MigratorFS
}

type NoMigrationsFoundError

type NoMigrationsFoundError struct {
	Path string
}

func (NoMigrationsFoundError) Error

func (e NoMigrationsFoundError) Error() string

Jump to

Keyboard shortcuts

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