migrate

package
v0.0.0-...-51ec7a6 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package migrate applies readable PostgreSQL migrations through Soro transactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	Owner      string
	Migrations []Migration
}

Group is one owner's ordered migration declaration.

type Migration

type Migration struct {
	Name string
	Up   []string
	Down []string
}

func LoadDir

func LoadDir(directory string) ([]Migration, error)

LoadDir loads convention-based .sql migrations in lexical filename order.

func LoadFile

func LoadFile(path string) (Migration, error)

LoadFile parses one migration with explicit Soro Up and Down sections.

func Parse

func Parse(name string, contents []byte) (Migration, error)

Parse parses one readable SQL migration from memory. It is intended for engine-owned migrations embedded in an external Go module.

type Migrator

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

func New

func New(db *database.DB) *Migrator

func (*Migrator) Apply

func (m *Migrator) Apply(ctx context.Context, migrations []Migration) error

func (*Migrator) Rollback

func (m *Migrator) Rollback(ctx context.Context, migrations []Migration, count int) error

func (*Migrator) Status

func (m *Migrator) Status(ctx context.Context, migrations []Migration) ([]Status, error)

type Plan

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

Plan is an immutable set of migration groups. Groups retain their declared order while migrations within a group retain lexical local order.

func NewPlan

func NewPlan(groups ...Group) (*Plan, error)

NewPlan validates and copies migration groups. The returned plan does not retain any caller-owned slices.

func (*Plan) Apply

func (plan *Plan) Apply(ctx context.Context, migrator *Migrator) error

Apply applies each group in declared order through the existing migrator.

func (*Plan) Groups

func (plan *Plan) Groups() []Group

Groups returns a deep copy of the plan's declarations.

func (*Plan) Migrations

func (plan *Plan) Migrations() []Migration

Migrations returns a deep-copied flattened declaration in group order.

func (*Plan) Rollback

func (plan *Plan) Rollback(ctx context.Context, migrator *Migrator, count int) error

Rollback rolls back the newest applied Soro migrations across all groups. The ledger order, rather than plan or prefixed-name order, determines which migrations run. River's separate migration tables are not consulted.

func (*Plan) Status

func (plan *Plan) Status(ctx context.Context, migrator *Migrator) ([]Status, error)

Status reports each group in declared order.

type Status

type Status struct {
	Owner     string
	Name      string
	Applied   bool
	AppliedAt *time.Time
}

Jump to

Keyboard shortcuts

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