migrate

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package migrate provides explicit migration planning and execution.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMigration reports malformed migration definitions.
	ErrInvalidMigration = errors.New("migrate: invalid migration")

	// ErrMigrationConflict reports conflicting migration history, such as an
	// applied version that is not present in the supplied migration list.
	ErrMigrationConflict = errors.New("migrate: migration conflict")
)

Functions

This section is empty.

Types

type AppliedMigration

type AppliedMigration struct {
	Version   int64
	Name      string
	AppliedAt time.Time
}

AppliedMigration records a migration already applied by a driver.

type Driver

type Driver interface {
	// EnsureSchema creates the migration metadata table if needed.
	EnsureSchema(ctx context.Context) error

	// Applied returns migrations already applied, keyed by version.
	Applied(ctx context.Context) (map[int64]AppliedMigration, error)

	// Apply applies migration and records it as applied atomically.
	Apply(ctx context.Context, migration Migration) error
}

Driver owns dialect-specific migration storage and execution.

type Migration

type Migration struct {
	Version int64
	Name    string
	SQL     []string
}

Migration is a versioned schema change.

SQL contains adapter-specific statements. The shared runner does not inspect or execute SQL directly; concrete database drivers decide how to apply each migration safely for their dialect.

func ApplyPending

func ApplyPending(ctx context.Context, driver Driver, migrations []Migration) ([]Migration, error)

ApplyPending applies every pending migration in ascending version order.

func Pending

func Pending(ctx context.Context, driver Driver, migrations []Migration) ([]Migration, error)

Pending returns migrations that have not been applied yet.

Jump to

Keyboard shortcuts

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