migrations

package
v0.0.0-...-a670c85 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMigrationFailed = errors.New("migration failed")
	ErrNoChange        = errors.New("no migration needed")
)
View Source
var Module = fx.Module("migrations",
	fx.Provide(func(pool *pgxpool.Pool, logger *slog.Logger, source MigrationSource) *Migrator {
		return NewMigrator(pool, logger, source.FS, source.Dir)
	}),
	fx.Invoke(runMigrationsIfEnabled),
)

Module provides migration functionality to the fx application. Requires MigrationSource to be provided by the main application.

Functions

func ProvideDBPool

func ProvideDBPool(pool *pgxpool.Pool) *pgxpool.Pool

ProvideDBPool is a helper to provide pgxpool.Pool for migration testing.

Types

type MigrationSource

type MigrationSource struct {
	FS  fs.FS
	Dir string
}

MigrationSource holds the embedded filesystem and directory for migrations.

type Migrator

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

Migrator handles database migrations.

func NewMigrator

func NewMigrator(pool *pgxpool.Pool, logger *slog.Logger, sourceFS fs.FS, sourceDir string) *Migrator

NewMigrator creates a new Migrator instance.

func (*Migrator) Run

func (m *Migrator) Run(ctx context.Context) error

Run executes all pending migrations.

func (*Migrator) Status

func (m *Migrator) Status(ctx context.Context) (version uint, dirty bool, err error)

Status returns the current migration version and dirty state.

Jump to

Keyboard shortcuts

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