golumn

package module
v0.0.0-...-81bd2b1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: BSD-3-Clause Imports: 15 Imported by: 0

README

golumn

Script Go database migrations with embedded Lua.

Documentation

Index

Constants

View Source
const (
	UpTargetLatest    = -1
	DownTargetInitial = -1
)

Variables

View Source
var (
	ErrLocked         = errors.New("version store is locked for writing")
	ErrInitialVersion = errors.New("initial version is current")
)

Functions

func GenScript

func GenScript(v int64, name string) (string, error)

func GenScriptTimestamp

func GenScriptTimestamp(name string) (version int64, filename string, script string, err error)

func WriteScript

func WriteScript(v int64, name string, p string) error

func WriteScriptTimestamp

func WriteScriptTimestamp(name string, dir string) (version int64, outpath string, err error)

Types

type GlobLoader

type GlobLoader struct {
	Pattern string
}

func (GlobLoader) Load

func (l GlobLoader) Load(ctx context.Context) ([]*Migration, error)

type Loader

type Loader interface {
	Load(context.Context) ([]*Migration, error)
}

type Migration

type Migration struct {
	Version  int64
	Name     string
	UpFunc   func(context.Context, *sql.DB) error
	DownFunc func(context.Context, *sql.DB) error
}

func Parse

func Parse(ctx context.Context, r io.Reader, name string) (*Migration, error)

func (*Migration) Down

func (m *Migration) Down(ctx context.Context, db *sql.DB) error

func (*Migration) Up

func (m *Migration) Up(ctx context.Context, db *sql.DB) error

type Migrator

type Migrator struct {
	Store   Store
	Sources []*Migration
	LogW    io.Writer
	DebugW  io.Writer

	HoldLockOnFailure bool
}

func (*Migrator) Down

func (m *Migrator) Down(ctx context.Context, to int64) (err error)

func (*Migrator) Up

func (m *Migrator) Up(ctx context.Context, to int64) (err error)

type Store

type Store interface {
	DB() *sql.DB
	Init(context.Context) error
	Lock(context.Context) error
	Release(context.Context) error
	Version(context.Context) (int64, error)
	Insert(context.Context, int64) error
	Remove(context.Context, int64) error
}

Directories

Path Synopsis
stores

Jump to

Keyboard shortcuts

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