migrate

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 {
	// 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