golazy.dev
–
golazy.dev
/
lazymigrate
Index
|
Files
|
Directories
package lazymigrate ¶
import "golazy.dev/lazymigrate"
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 BackendMigration ¶
type BackendMigration struct {
ID string
}
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
func (c *Catalog) Add ¶
func (c *Catalog) Add(database string, source Source) error
func (c *Catalog) LoadMigrations ¶
func (c *Catalog) LoadMigrations(ctx context.Context, database string) ([]Migration, error)
func (c *Catalog) Sources ¶
func (c *Catalog) Sources(database string) []Source
type Config ¶
type Config struct {
Backend Backend
Sources []Source
}
type Direction ¶
type Direction string
type FS ¶
type FS struct {
Files fs.FS
Dir string
}
func ForDatabase ¶
func ForDatabase(files fs.FS, database string) FS
func (source FS) LoadMigrations ¶
func (source FS) LoadMigrations(ctx context.Context) ([]Migration, error)
type Migration ¶
type Migration struct {
ID string
Prefix string
Timestamp string
Path string
Content []byte
}
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)
type Plan ¶
type Plan struct {
Steps []Step
}
func (p Plan) Empty ¶
func (p Plan) Empty() bool
type Source ¶
type Source interface {
LoadMigrations(context.Context) ([]Migration, error)
}
type SourceFunc ¶
type SourceFunc func(context.Context) ([]Migration, error)
func (fn SourceFunc) LoadMigrations ¶
func (fn SourceFunc) LoadMigrations(ctx context.Context) ([]Migration, error)
type State ¶
type State string
type Status ¶
type Status struct {
ID string
State State
Migration Migration
BackendMigration BackendMigration
}
type Step ¶
type Step struct {
Direction Direction
Migration Migration
}
Directories ¶
| Path | Synopsis |
|---|---|
| lazymigrate/fakemigrator | Package fakemigrator provides an in-memory lazymigrate backend for tests. |
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.