migrate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package migrate provides a minimal database schema migration runner.

Index

Constants

View Source
const (
	// DefaultTableName is the table used to track applied migrations.
	DefaultTableName = "rain_schema_migrations"
)

Variables

View Source
var (
	// ErrDuplicateMigrationID is returned when the same migration ID appears more than once.
	ErrDuplicateMigrationID = errors.New("migrate: duplicate migration id")
	// ErrEmptyMigrationID is returned when a migration ID is blank.
	ErrEmptyMigrationID = errors.New("migrate: migration id is required")
	// ErrNilMigrationUp is returned when a migration has a nil Up function.
	ErrNilMigrationUp = errors.New("migrate: migration up function is required")
)

Functions

This section is empty.

Types

type ApplyResult

type ApplyResult struct {
	AppliedIDs []string
}

ApplyResult summarizes one ApplyPending run.

func ApplyPending

func ApplyPending(ctx context.Context, db *sql.DB, migrations []Migration) (ApplyResult, error)

ApplyPending applies pending migrations using the default migration table.

type Executor

type Executor interface {
	ExecContext(context.Context, string, ...any) (sql.Result, error)
}

Executor executes SQL statements.

type Migration

type Migration struct {
	ID string
	// Up is the forward migration function.
	Up Operation
	// Down is reserved for future rollback support.
	// v1 runner behavior is forward-only.
	Down Operation
	// NonTransactional disables the per-migration transaction wrapper.
	NonTransactional bool
}

Migration defines one ordered schema change.

type Operation

type Operation func(context.Context, Executor) error

Operation applies one side of a migration.

type Runner

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

Runner applies migrations and tracks their state in a schema table.

func NewRunner

func NewRunner(tableName string) *Runner

NewRunner creates a migration runner.

func (*Runner) ApplyPending

func (r *Runner) ApplyPending(ctx context.Context, db *sql.DB, migrations []Migration) (ApplyResult, error)

ApplyPending applies migrations that are not yet recorded in the migration table.

Jump to

Keyboard shortcuts

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