Help us shape the future of Go! Take the 2026 Go Developer Survey

migrator

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

type Migration struct {
	Version  int64
	Name     string
	Dir      string // "up" or "down"
	File     string
	SQL      string
	Checksum string
}

Migration is a versioned SQL change.

type Options

type Options struct {
	// MigrationsDir is kept for backward compatibility. If non-empty,
	// it will be appended to MigrationsDirs.
	MigrationsDir string
	// MigrationsDirs allows loading migrations from multiple directories.
	// Directories are processed in order; later files with the same name
	// override earlier ones before parsing.
	MigrationsDirs []string
	// EmbeddedFSs allows loading migrations from multiple embedded
	// filesystems. Each is expected to contain a "migrations" directory.
	// Embedded filesystems are appended after explicit directories.
	EmbeddedFSs []fs.FS
	TableName   string
	LockKey     int64
	// AllowDangerousDown enables Down(); keep disabled in API binaries.
	AllowDangerousDown bool
	// Logger outputs formatted status messages.
	Logger func(format string, args ...any)
}

Options configures the runner.

type Runner

type Runner struct {
	DB   *sql.DB
	Opts Options
	// contains filtered or unexported fields
}

Runner executes SQL migrations transactionally and records state.

func New

func New(db *sql.DB, opts Options) *Runner

func (*Runner) Down

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

Down reverts the latest successfully applied version by 1 step.

func (*Runner) Status

func (r *Runner) Status(ctx context.Context) (string, error)

Status reports current and pending state.

func (*Runner) Up

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

Up applies all pending "up" migrations.

Jump to

Keyboard shortcuts

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