migrate

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStoreNotInitialized = fmt.Errorf("store not initialized")
)

Functions

func Validate

func Validate(file *File) error

Validate a migration file

Types

type Execer

type Execer interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
}

Execer is an interface for executing sql statements

type File

type File struct {
	Name     string
	Contents []byte
}

File represents a single migration file

func LoadFiles

func LoadFiles(dir string) ([]*File, error)

LoadFiles from a given directory

type Migrate

type Migrate struct {
	StoreConn  StoreConn
	TargetConn Execer
	Key        string
	Files      []*File
	// contains filtered or unexported fields
}

Migrate is a mechanism to check and run migrations

func New

func New(storedb StoreConn, targetdb Execer, key string, files []*File) *Migrate

func (*Migrate) Run

func (m *Migrate) Run(ctx context.Context, filename string) (*Migration, error)

Run the next migration

func (*Migrate) Status

func (m *Migrate) Status(ctx context.Context) (*Status, error)

Status returns the status of migrations

type Migration

type Migration struct {
	// Filename from row, file or both
	Filename string

	// Database row if present
	Row *store.RoachMigration

	// File if present
	File *File
}

Migration represents a single migration

type Status

type Status struct {
	Key        string
	Migrations []*Migration

	// All migrations are complete
	InSync bool

	// Previous migrations have errors
	HasErrors bool

	// NextMigraiton to run (nil if none)
	NextMigration *Migration
}

Status of all migrations

type StoreConn

type StoreConn interface {
	store.DBTX
	Begin(ctx context.Context) (pgx.Tx, error)
}

StoreConn is an interface for a connection to the store

Jump to

Keyboard shortcuts

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