migrate

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoChange = migrate.ErrNoChange

ErrNoChange is returned when there's nothing to migrate.

Functions

This section is empty.

Types

type Engine

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

Engine is the main migration runner. It wraps golang-migrate/migrate with a simpler API.

func New

func New(cfg *config.Config) (*Engine, error)

New creates a new migration engine from a config. It validates the config, builds the DSN, and initializes golang-migrate.

func (*Engine) Close

func (e *Engine) Close() error

Close releases all resources held by the engine. Always call this when done (use defer engine.Close()).

func (*Engine) Create

func (e *Engine) Create(name string) (upPath, downPath string, err error)

Create creates a new migration file pair (up and down) with the given name. Returns an error if a migration with the same name already exists. Returns the paths of the created files.

func (*Engine) Down

func (e *Engine) Down(n int) error

Down reverts the last N applied migrations. Use Down(1) to revert only the most recent one (safe default).

func (*Engine) DownAll

func (e *Engine) DownAll() error

DownAll reverts ALL applied migrations. This is destructive — use with caution!

func (*Engine) Force

func (e *Engine) Force(version int) error

Force sets the migration version without running any migrations. Useful for fixing a "dirty" state when a migration failed mid-way. Passing -1 resets the version to nothing.

func (*Engine) List

func (e *Engine) List() ([]MigrationFile, error)

List returns all migration files found in the migrations directory. Does NOT query the database — just reads files from disk.

func (*Engine) Up

func (e *Engine) Up() error

Up applies all pending migrations. Returns ErrNoChange if there's nothing to apply.

func (*Engine) UpN

func (e *Engine) UpN(n int) error

UpN applies the next N pending migrations. Use UpN(1) to apply only the next one.

func (*Engine) Version

func (e *Engine) Version() (version uint, dirty bool, err error)

Version returns the current migration version and whether the state is dirty. A dirty state means a migration failed partway and needs manual intervention. Returns (0, false, nil) if no migrations have been applied yet.

type MigrationFile

type MigrationFile struct {
	Version  uint
	Name     string
	UpPath   string
	DownPath string
}

MigrationFile represents a single migration on disk.

Jump to

Keyboard shortcuts

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