clpgxmigrate

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaulCollection = NewCollection()
View Source
var DefaultOptions = []Option{
	VersionSchemaName("schema_migrate"),
	VersionTableName("schema_version"),
	WithCollection(DefaulCollection),
	WithLocker(NewPostgresAdvisoryLocker(advisoryLockNumber)),
	WithLogger(NewSLogLogger(slog.Default())),
}

Functions

func NumericFromFilename

func NumericFromFilename(filename string) (int64, error)

func Register

func Register(up Step)

func VersionsToApply

func VersionsToApply(versions []int64, current, target int64) (result []int64)

Types

type ApplyError

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

func (ApplyError) Error

func (e ApplyError) Error() string

func (ApplyError) Unwrap

func (e ApplyError) Unwrap() error

type Collection

type Collection interface {
	Step(version int64) (Step, bool)
	Versions() []int64
	Register(filename string, step Step) error
}

func NewCollection

func NewCollection() Collection

type Locker

type Locker interface {
	Lock(ctx context.Context, conn *pgx.Conn) error
	Unlock(ctx context.Context, conn *pgx.Conn) error
}

func NewPostgresAdvisoryLocker

func NewPostgresAdvisoryLocker(num int64) Locker

type Logger

type Logger interface {
	LogNoVersionToApply(ctx context.Context, all, toApply []int64, currentVersion, targetVersion int64)
	LogVersionsToApply(ctx context.Context, all, toApply []int64, currentVersion, targetVersion int64)
	LogVersionApplyStart(ctx context.Context, version int64)
	LogVersionApplyDone(ctx context.Context, version int64)
}

func NewSLogLogger

func NewSLogLogger(logs *slog.Logger) Logger

type Option

type Option func(*opts)

func VersionSchemaName

func VersionSchemaName(s string) Option

func VersionTableName

func VersionTableName(s string) Option

func WithCollection

func WithCollection(c Collection) Option

func WithLocker

func WithLocker(l Locker) Option

func WithLogger

func WithLogger(l Logger) Option

type Provider

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

func New

func New(conn *pgx.Conn, os ...Option) *Provider

func NewProvider

func NewProvider(
	conn *pgx.Conn,
	os ...Option,
) *Provider

func (*Provider) Migrate

func (p *Provider) Migrate(ctx context.Context, targetVersion int64) (*Result, error)

func (*Provider) ReadSchemaVersion

func (p *Provider) ReadSchemaVersion(ctx context.Context) (version int64, err error)

func (*Provider) Status

func (p *Provider) Status(ctx context.Context) (status *Status, err error)

func (*Provider) UpdateSchemaVersion

func (p *Provider) UpdateSchemaVersion(ctx context.Context, version int64) error

type RegisterError

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

func (RegisterError) Error

func (e RegisterError) Error() string

func (RegisterError) Unwrap

func (e RegisterError) Unwrap() error

type Result

type Result struct {
	AppliedVersions []int64
}

type Status

type Status struct {
	CurrentVersion int64
}

type Step

type Step interface {
	Apply(ctx context.Context, conn *pgx.Conn) error
}

func NewStep

func NewStep[T StepFunc](fn T) Step

type StepFunc

type StepFunc interface {
	~func(context.Context, pgx.Tx) error | ~func(context.Context, *pgx.Conn) error
}

Jump to

Keyboard shortcuts

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