Documentation
¶
Index ¶
- Variables
- func Apply(ctx context.Context, migrator *migrate.Migrate, direction Direction, ...) error
- func FormatTargets() string
- func IncompatibleError(status Status) error
- func LatestVersion(fsys fs.FS, directory string) (uint, error)
- func OnlyUnavailable(err error) bool
- func ValidateRequest(status Status, direction Direction, version *uint) error
- type Direction
- type State
- type Status
- func Inspect(ctx context.Context, target Target, cfg *config.Database, table string, ...) Status
- func NewStatus(target Target, provider config.DatabaseProvider, current *uint, available uint, ...) Status
- func UnavailableStatus(target Target, provider config.DatabaseProvider, available uint, err error) Status
- type Target
- type UnavailableError
Constants ¶
This section is empty.
Variables ¶
var OrderedTargets = []Target{ TargetMainDatabase, TargetWorkflows, TargetAppMetrics, }
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 ¶
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 ¶
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 ¶
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 ¶
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 Status ¶
type Status struct {
Target Target
Provider config.DatabaseProvider
CurrentVersion *uint
AvailableVersion uint
Dirty bool
State State
Err error
}
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 (Status) Compatible ¶
func (Status) CurrentVersionString ¶
type UnavailableError ¶
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.