schemadance

package module
v0.0.0-...-989d483 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: BSD-2-Clause Imports: 3 Imported by: 0

README

schemadance

Postgresql schema migration library for Go

Usage

Create a directory with files called, e.g, schema.1.up.sql, schema.1.down.sql or, equivalently, schema.0-1.sql, schema.1-0.sql.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Db

type Db interface {
	Initialize(ctx context.Context) error
	Begin(ctx context.Context) (Tx, error)
	Close(ctx context.Context) error
}

type Migrator

type Migrator struct {
	Database Db
	Patches  PatchSets
	Partial  bool
	Status   chan Status
}

func (Migrator) Migrate

func (m Migrator) Migrate(ctx context.Context, set string, to int) error

func (Migrator) Update

func (m Migrator) Update(ctx context.Context) error

func (Migrator) Version

func (m Migrator) Version(ctx context.Context, set string) (ver int, rerr error)

type Patch

type Patch struct {
	Prefix      string
	From        int
	To          int
	Description string
	Filename    string
	Before      func(ctx context.Context, tx Tx, from, to int) error
	After       func(ctx context.Context, tx Tx, from, to int) error
}

func Plan

func Plan(from int, to int, set PatchSet) ([]Patch, error)

type PatchSet

type PatchSet struct {
	Name string
	Up   []Patch
	Down []Patch
}

func (PatchSet) EndVersion

func (p PatchSet) EndVersion() int

func (PatchSet) SQLOnly

func (p PatchSet) SQLOnly() bool

func (PatchSet) StartVersion

func (p PatchSet) StartVersion() int

type PatchSets

type PatchSets struct {
	Sets  []PatchSet
	Files fs.FS
}

type Status

type Status struct {
	Prefix      string
	From        int
	To          int
	Description string
	Filename    string
	Phase       StatusPhase
}

type StatusPhase

type StatusPhase int
const (
	Start StatusPhase = iota
	End
	Failed
)

type Tx

type Tx interface {
	Exec(ctx context.Context, sql string) error
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
	Version(ctx context.Context, prefix string) (int, error)
	SetVersion(ctx context.Context, prefix string, version int) error
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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