migrate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLockTimeout = errors.New("migration lock timeout")

ErrLockTimeout indicates a lock timeout.

Functions

This section is empty.

Types

type AdvisoryLocker

type AdvisoryLocker struct {
	ID           int64
	Timeout      time.Duration
	PollInterval time.Duration
}

AdvisoryLocker uses PostgreSQL advisory locks.

func (AdvisoryLocker) Lock

func (a AdvisoryLocker) Lock(ctx context.Context, db *sql.DB) error

Lock acquires a PostgreSQL advisory lock.

func (AdvisoryLocker) Unlock

func (a AdvisoryLocker) Unlock(ctx context.Context, db *sql.DB) error

Unlock releases a PostgreSQL advisory lock.

type Locker

type Locker interface {
	Lock(context.Context, *sql.DB) error
	Unlock(context.Context, *sql.DB) error
}

Locker handles migration locking.

type Migration

type Migration struct {
	Version  int
	Name     string
	UpPath   string
	DownPath string
}

Migration describes a migration pair.

func List

func List(dir string) ([]Migration, error)

List returns migrations found in a directory.

type PlanEntry

type PlanEntry struct {
	Migration
	Applied bool
}

PlanEntry describes a migration and whether it has been applied.

type Runner

type Runner struct {
	DB     *sql.DB
	Dir    string
	Table  string
	Locker Locker
}

Runner executes migrations from a directory.

func New

func New(db *sql.DB, dir string) *Runner

New creates a new Runner.

func (*Runner) Down

func (r *Runner) Down(ctx context.Context, steps int) (int, error)

Down rolls back the latest migrations.

func (*Runner) Plan

func (r *Runner) Plan(ctx context.Context) ([]PlanEntry, error)

Plan returns a migration plan, optionally marking applied migrations.

func (*Runner) Up

func (r *Runner) Up(ctx context.Context) (int, error)

Up applies all pending migrations.

Jump to

Keyboard shortcuts

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