manager

package
v0.0.0-...-61b9b26 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterBackend

func RegisterBackend(name string, b DBBackend)

RegisterBackend registers a backend implementation by name.

Types

type DBBackend

type DBBackend interface {
	DriverName() string
	NewDriver(db *sql.DB) (database.Driver, error)
	Validator() validate.Dialect
}

DBBackend abstracts database specific logic for migrations.

func GetBackend

func GetBackend(name string) (DBBackend, bool)

GetBackend returns the backend registered for driver name.

type Manager

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

Manager wraps golang-migrate with retries, logging, notifications, and resource handling.

func NewManager

func NewManager(backend DBBackend, dsn, migrationsDir string, retries int, logger *logrus.Entry, actor string, strict bool, confirmFn validate.ConfirmFunc, note notifier.Notifier) (*Manager, error)

NewManager creates a Manager. It limits DB pool to 1 connection to ensure advisory locks (used internally by the Postgres driver) apply correctly.

func (*Manager) Close

func (mgr *Manager) Close() error

Close cleans up resources.

func (*Manager) CommitAll

func (mgr *Manager) CommitAll() error

CommitAll marks all rows in migrations_history as committed.

func (*Manager) Down

func (mgr *Manager) Down() error

Down rolls back all applied migrations.

func (*Manager) Force

func (mgr *Manager) Force(version int) error

Force sets the DB to a specific version and clears the dirty flag.

func (*Manager) SafeForce

func (mgr *Manager) SafeForce(target int) error

SafeForce only allows forcing down by one if dirty, and never up beyond last file.

func (*Manager) Status

func (mgr *Manager) Status() (uint, int, error)

Status returns (currentVersion, pendingCount, error).

func (*Manager) Steps

func (mgr *Manager) Steps(n int) error

Steps migrates exactly n steps (negative to rollback).

func (*Manager) Up

func (mgr *Manager) Up() error

func (*Manager) Version

func (mgr *Manager) Version() (uint, bool, error)

Version returns (currentVersion, dirtyFlag, error).

func (*Manager) VersionCommitted

func (mgr *Manager) VersionCommitted(v uint) (bool, error)

versionCommitted reports whether the given version has been committed.

type PostgresBackend

type PostgresBackend struct{}

PostgresBackend implements DBBackend for PostgreSQL databases.

func (PostgresBackend) DriverName

func (PostgresBackend) DriverName() string

func (PostgresBackend) NewDriver

func (PostgresBackend) NewDriver(db *sql.DB) (database.Driver, error)

func (PostgresBackend) Validator

func (PostgresBackend) Validator() validate.Dialect

Jump to

Keyboard shortcuts

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