golazy.dev golazy.dev / lazymigrate Index | Files | Directories

package lazymigrate

import "golazy.dev/lazymigrate"

Package lazymigrate loads, plans, and applies file-based migrations through backend-owned execution.

The package is intentionally backend-agnostic. It loads migration files, diffs them against the migrations a backend reports as already applied, and asks that backend to run concrete up or down steps. The backend owns the migration file format, locking, transactions, schema storage, and metadata tables.

Applications can load migrations from an fs.FS, combine application and package-provided sources in a Catalog, and then run a Migrator with a chosen Backend. The fakemigrator subpackage provides an in-memory backend for tests and early command wiring.

Types

type Backend

type Backend interface {
	Setup(context.Context) error
	List(context.Context) ([]BackendMigration, error)
	Run(context.Context, Step) error
	DumpSchema(context.Context) ([]byte, error)
	LoadSchema(context.Context, []byte) error
}

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}
func New
func New(config Config) (*Migrator, error)
func (m *Migrator) Apply
func (m *Migrator) Apply(ctx context.Context, plan Plan) error
func (m *Migrator) Down
func (m *Migrator) Down(ctx context.Context, limit int) (Plan, error)
func (m *Migrator) DumpSchema
func (m *Migrator) DumpSchema(ctx context.Context) ([]byte, error)
func (m *Migrator) List
func (m *Migrator) List(ctx context.Context) ([]Status, error)
func (m *Migrator) LoadSchema
func (m *Migrator) LoadSchema(ctx context.Context, schema []byte) error
func (m *Migrator) PlanDown
func (m *Migrator) PlanDown(ctx context.Context, limit int) (Plan, error)
func (m *Migrator) PlanRedo
func (m *Migrator) PlanRedo(ctx context.Context, limit int) (Plan, error)
func (m *Migrator) PlanUp
func (m *Migrator) PlanUp(ctx context.Context, limit int) (Plan, error)
func (m *Migrator) Redo
func (m *Migrator) Redo(ctx context.Context, limit int) (Plan, error)
func (m *Migrator) Setup
func (m *Migrator) Setup(ctx context.Context) error
func (m *Migrator) Up
func (m *Migrator) Up(ctx context.Context, limit int) (Plan, error)

Directories

Path Synopsis
lazymigrate/fakemigrator Package fakemigrator provides an in-memory lazymigrate backend for tests.