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

migration

package
v0.0.0-...-40c6b5d Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Apply

func Apply(
	ctx context.Context,
	migrator *migrate.Migrate,
	direction Direction,
	version *uint,
) error

Apply runs a migration in the specified direction. If version is specified it migrates to the specified version. If it is not specified it defaults to the latest migration. This method handles context cancellation with graceful stop on the migration goroutine.

func FormatTargets

func FormatTargets() string

func IncompatibleError

func IncompatibleError(status Status) error

IncompatibleError returns nil when status is compatible with this binary. Otherwise it describes the problem: an *UnavailableError when the status could not be read, or a plain error for stale, ahead, or dirty schemas.

func LatestVersion

func LatestVersion(fsys fs.FS, directory string) (uint, error)

LatestVersion returns the latest available migration version by walking the migrations in the specified directory of the filesystem. In practice this will be applied to an embedded filesystem that contains the database migration SQL files.

func OnlyUnavailable

func OnlyUnavailable(err error) bool

OnlyUnavailable reports whether err consists solely of UnavailableError values, looking through fmt.Errorf wrapping and errors.Join trees. It is false for nil and for any tree containing another kind of error, such as a stale or dirty schema, which retrying cannot fix.

func ValidateRequest

func ValidateRequest(status Status, direction Direction, version *uint) error

ValidateRequest validates the migration request by comparing the `status` of the database (current version, dirty, available migrations, etc) against the requested migration direction and version. It returns a descriptive error if the request is invalid.

Types

type Direction

type Direction string
const (
	DirectionUp   Direction = "up"
	DirectionDown Direction = "down"
)

func ParseDirection

func ParseDirection(value string) (Direction, error)

type State

type State string
const (
	StateCurrent     State = "current"
	StateBehind      State = "behind"
	StateAhead       State = "ahead"
	StateDirty       State = "dirty"
	StateMissing     State = "missing"
	StateUnavailable State = "unavailable"
)

type Status

type Status struct {
	Target           Target
	Provider         config.DatabaseProvider
	CurrentVersion   *uint
	AvailableVersion uint
	Dirty            bool
	State            State
	Err              error
}

func Inspect

func Inspect(
	ctx context.Context,
	target Target,
	cfg *config.Database,
	table string,
	available uint,
) Status

func NewStatus

func NewStatus(
	target Target,
	provider config.DatabaseProvider,
	current *uint,
	available uint,
	dirty bool,
) Status

NewStatus returns a new Status computing state based on the information provided.

func UnavailableStatus

func UnavailableStatus(
	target Target,
	provider config.DatabaseProvider,
	available uint,
	err error,
) Status

func (Status) Compatible

func (s Status) Compatible() bool

func (Status) CurrentVersionString

func (s Status) CurrentVersionString() string

type Target

type Target string
const (
	TargetMainDatabase Target = "main-database"
	TargetWorkflows    Target = "workflows"
	TargetAppMetrics   Target = "app-metrics"
	TargetAll          Target = "all"
)

func ParseTarget

func ParseTarget(value string, allowAll bool) (Target, error)

ParseTarget parses a string value into a Target. If the target is not valid, an error is returned.

type UnavailableError

type UnavailableError struct {
	// Target is the schema target whose status could not be read.
	Target Target
	// Err is the underlying failure.
	Err error
}

UnavailableError reports that a schema target's migration state could not be read, typically because its database was unreachable or rejected the query. Unlike a stale or dirty schema, it can resolve without operator action, so callers may retry it.

func (*UnavailableError) Error

func (e *UnavailableError) Error() string

Error implements error, preserving the historical message format.

func (*UnavailableError) Unwrap

func (e *UnavailableError) Unwrap() error

Unwrap exposes the underlying failure to errors.Is / errors.As.

Jump to

Keyboard shortcuts

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