migration

package
v1.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHashMismatch is returned when a changeset was already applied, but the queries changed.
	ErrHashMismatch = errors.New("migration: hash does not match already applied version")
	// ErrNameTooLong is returned when a changeset name exceeds the limit.
	ErrNameTooLong = errors.New("migration: changeset name too long (max. 256)")
)

Functions

This section is empty.

Types

type Changeset

type Changeset interface {
	// Name returns the name of the changeset.
	// It is used to keep track of already applied changesets.
	Name() string
	// Queries returns the content of this changeset as raw sql.
	Queries() (string, error)
}

Changeset represents a series of related queries to advance the database schema.

func ChangesetsFromFolder

func ChangesetsFromFolder(filesystem fs.FS) ([]Changeset, error)

func FileChangeset

func FileChangeset(filesystem fs.FS, name string) Changeset

func LiteralChangeset

func LiteralChangeset(name, queries string) Changeset

func Up

func Up(ctx context.Context, changesets []Changeset, opts *Options) ([]Changeset, error)

Up applies all changesets in order, if they have not already been applied. All changesets are applied within a transaction. When an error occurs, the process will stop, but previously applied changesets won't be rolled back. When a changeset was already applied, but does not match in content, an errors is returned. Up expects a groundwork/noorm.Querier to be present in the context (see WithDatabase).

type Options

type Options struct {
	// ChangelogTablename is the name of the table used to track already applied changesets.
	ChangelogTablename string
}

Jump to

Keyboard shortcuts

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