migrations

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const CorePluginID = "core"

CorePluginID identifies the core migrations set.

View Source
const (
	DefaultSchemaTable = "auth_schema_migrations"
)

DefaultSchemaTable is the shared table storing migration metadata.

Variables

This section is empty.

Functions

func ExecStatements

func ExecStatements(ctx context.Context, tx bun.Tx, statements ...string) error

ExecStatements executes statements sequentially, skipping blanks.

Types

type AppliedMigration

type AppliedMigration struct {
	PluginID  string
	Version   string
	AppliedAt time.Time
}

AppliedMigration represents a persisted migration entry for introspection.

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

Logger is a minimal logging interface used by the migrator.

type Migration

type Migration struct {
	Version string
	Up      func(ctx context.Context, tx bun.Tx) error
	Down    func(ctx context.Context, tx bun.Tx) error
}

Migration represents a single schema change with reversible logic.

func ForProvider

func ForProvider(provider string, variants ProviderVariants) []Migration

ForProvider returns the migrations for the requested provider using the supplied variants.

type MigrationSet

type MigrationSet struct {
	PluginID   string
	DependsOn  []string
	Migrations []Migration
}

MigrationSet groups migrations under a plugin identifier with optional dependencies.

func CoreMigrationSet

func CoreMigrationSet(provider string) (MigrationSet, error)

CoreMigrationSet returns the programmatic migrations for the core schema.

type Migrator

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

Migrator orchestrates plugin-aware migrations backed by Bun transactions.

func NewMigrator

func NewMigrator(db bun.IDB, logger Logger, opts ...MigratorOption) (*Migrator, error)

NewMigrator constructs a Migrator backed by the provided Bun database.

func (*Migrator) ListApplied

func (m *Migrator) ListApplied(ctx context.Context, pluginID string) ([]schemaMigration, error)

ListApplied returns applied migrations for all plugins or a specific plugin when pluginID is provided.

func (*Migrator) Migrate

func (m *Migrator) Migrate(ctx context.Context, sets []MigrationSet) error

Migrate applies all pending migrations respecting plugin dependencies.

func (*Migrator) RollbackAll

func (m *Migrator) RollbackAll(ctx context.Context, sets []MigrationSet) error

RollbackAll executes Down migrations for the provided sets in reverse dependency order.

func (*Migrator) RollbackLast

func (m *Migrator) RollbackLast(ctx context.Context, set MigrationSet) error

RollbackLast rolls back the most recent migration applied for a plugin in the provided set.

type MigratorOption

type MigratorOption func(*Migrator)

MigratorOption configures optional Migrator behavior.

func WithTableName

func WithTableName(name string) MigratorOption

WithTableName overrides the schema migrations table name.

type ProviderVariants

type ProviderVariants map[string]func() []Migration

ProviderVariants maps a database provider to a lazy migration constructor.

Jump to

Keyboard shortcuts

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