migrate

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package migrate provides database migration runners and CLI commands.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedDialect = errors.New("unsupported migration dialect")

ErrUnsupportedDialect reports that a migration dialect is not supported.

Functions

func Command

func Command(runner Runner) cli.Command

Command returns a migrate command with up, down, reset, and status subcommands.

Types

type Dialect

type Dialect string

Dialect identifies a database migration dialect.

const (
	// DialectPostgres runs migrations against Postgres.
	DialectPostgres Dialect = "postgres"
	// DialectSQLite runs migrations against SQLite.
	DialectSQLite Dialect = "sqlite"
)

type GooseRunner

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

GooseRunner applies migrations with goose.

func New

func New(db *sql.DB, dialect Dialect, migrations fs.FS, opts ...Option) (*GooseRunner, error)

New creates a goose-backed migration runner. The caller owns db and remains responsible for closing it.

func NewFromDir

func NewFromDir(db *sql.DB, dialect Dialect, dir string, opts ...Option) (*GooseRunner, error)

NewFromDir creates a goose-backed migration runner from a local directory.

func (*GooseRunner) Down

func (r *GooseRunner) Down(ctx context.Context) (Result, error)

Down rolls back one migration.

func (*GooseRunner) Reset

func (r *GooseRunner) Reset(ctx context.Context) ([]Result, error)

Reset rolls back all applied migrations.

func (*GooseRunner) Status

func (r *GooseRunner) Status(ctx context.Context) ([]Status, error)

Status returns migration state.

func (*GooseRunner) Up

func (r *GooseRunner) Up(ctx context.Context) ([]Result, error)

Up applies all pending migrations.

type Option

type Option func(*gooseOptions)

Option configures a GooseRunner.

func WithTableName

func WithTableName(tableName string) Option

WithTableName configures the migration version table name.

type Result

type Result struct {
	Version   int64
	Source    string
	Direction string
	Duration  time.Duration
	Empty     bool
	Skipped   bool
}

Result describes one applied migration.

type Runner

type Runner interface {
	Up(context.Context) ([]Result, error)
	Down(context.Context) (Result, error)
	Reset(context.Context) ([]Result, error)
	Status(context.Context) ([]Status, error)
}

Runner applies and inspects database migrations.

type Status

type Status struct {
	Version   int64
	Source    string
	State     string
	AppliedAt time.Time
}

Status describes one migration status row.

Jump to

Keyboard shortcuts

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