migration

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: MIT Imports: 12 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// Flag is a logger event flag.
	Flag logger.Flag = "db.migration"

	// FlagStats is a logger event flag.
	FlagStats logger.Flag = "db.migration.stats"
)
View Source
const (
	// StatApplied is a stat name.
	StatApplied = "applied"
	// StatFailed is a stat name.
	StatFailed = "failed"
	// StatSkipped is a stat name.
	StatSkipped = "skipped"
	// StatTotal is a stat name.
	StatTotal = "total"
)

Variables

This section is empty.

Functions

func NoOp

func NoOp(c *db.Connection, tx *sql.Tx) error

NoOp performs no action.

Types

type DataFileReader

type DataFileReader struct {
	// contains filtered or unexported fields
}

DataFileReader reads a postgres dump.

func ReadDataFile

func ReadDataFile(filePath string) *DataFileReader

ReadDataFile returns a new DataFileReader

func (*DataFileReader) Apply

func (dfr *DataFileReader) Apply(c *db.Connection, tx *sql.Tx) (err error)

Apply applies the file reader.

func (*DataFileReader) Invoke

func (dfr *DataFileReader) Invoke(suite *Suite, group *Group, c *db.Connection, tx *sql.Tx) error

Invoke implements the invocable interface.

func (*DataFileReader) Label

func (dfr *DataFileReader) Label() string

Label returns the label for the data file reader.

func (*DataFileReader) WithLabel

func (dfr *DataFileReader) WithLabel(value string) *DataFileReader

WithLabel sets the migration label.

type Event

type Event struct {
	*logger.EventMeta
	// contains filtered or unexported fields
}

Event is a migration logger event.

func NewEvent

func NewEvent(result, body string, labels ...string) *Event

NewEvent returns a new event.

func (Event) WriteJSON

func (e Event) WriteJSON() logger.JSONObj

WriteJSON implements logger.JSONWritable.

func (Event) WriteText

func (e Event) WriteText(tf logger.TextFormatter, buf *bytes.Buffer)

WriteText writes the migration event as text.

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group is an atomic series of migrations. It uses transactions to apply a set of sub-migrations as a unit.

func NewGroup

func NewGroup(steps ...Invocable) *Group

NewGroup creates a new migration group.

func (*Group) Invoke

func (g *Group) Invoke(suite *Suite, c *db.Connection) (err error)

Invoke runs the steps in a transaction.

func (*Group) Label

func (g *Group) Label() string

Label returns a label for the runner.

func (*Group) WithLabel

func (g *Group) WithLabel(value string) *Group

WithLabel sets the migration label.

func (*Group) WithSteps

func (g *Group) WithSteps(steps ...Invocable) *Group

WithSteps adds steps to the group.

type GuardFunc

type GuardFunc func(*Suite, *Group, *Step, *db.Connection, *sql.Tx) error

GuardFunc is a control for migration steps.

func AlwaysRun

func AlwaysRun() GuardFunc

AlwaysRun always runs a step.

func ColumnExists

func ColumnExists(tableName, columnName string) GuardFunc

ColumnExists alters an existing column, erroring if it doesn't exist

func ColumnNotExists

func ColumnNotExists(tableName, columnName string) GuardFunc

ColumnNotExists creates a table on the given connection if it does not exist.

func ConstraintExists

func ConstraintExists(constraintName string) GuardFunc

ConstraintExists alters an existing constraint, erroring if it doesn't exist

func ConstraintNotExists

func ConstraintNotExists(constraintName string) GuardFunc

ConstraintNotExists creates a table on the given connection if it does not exist.

func Guard

func Guard(description string, evaluator func(c *db.Connection, tx *sql.Tx) (bool, error)) GuardFunc

Guard returns a function that determines if a step in a group should run.

func IfExists

func IfExists(statement string) GuardFunc

IfExists only runs the statement if the given item exists.

func IfNotExists

func IfNotExists(statement string) GuardFunc

IfNotExists only runs the statement if the given item doesn't exist.

func IndexExists

func IndexExists(tableName, indexName string) GuardFunc

IndexExists alters an existing index, erroring if it doesn't exist

func IndexNotExists

func IndexNotExists(tableName, indexName string) GuardFunc

IndexNotExists creates a index on the given connection if it does not exist.

func RoleExists

func RoleExists(roleName string) GuardFunc

RoleExists alters an existing role in the db

func RoleNotExists

func RoleNotExists(roleName string) GuardFunc

RoleNotExists creates a new role if it doesn't exist.

func TableExists

func TableExists(tableName string) GuardFunc

TableExists alters an existing table, erroring if it doesn't exist

func TableNotExists

func TableNotExists(tableName string) GuardFunc

TableNotExists creates a table on the given connection if it does not exist.

type Invocable

type Invocable interface {
	Label() string
	Invoke(*Suite, *Group, *db.Connection, *sql.Tx) error
}

Invocable is a thing that can be invoked.

type InvocableFunc

type InvocableFunc func(c *db.Connection, tx *sql.Tx) error

InvocableFunc is a function that can be run during a migration step.

func Actions

func Actions(actions ...InvocableFunc) InvocableFunc

Actions returns an invocable of a set of actions.

func Statements

func Statements(statements ...string) InvocableFunc

Statements is an alias to Body(...Statement(stmt))

type StatsEvent

type StatsEvent struct {
	*logger.EventMeta
	// contains filtered or unexported fields
}

StatsEvent is a migration logger event.

func NewStatsEvent

func NewStatsEvent(applied, skipped, failed, total int) *StatsEvent

NewStatsEvent returns a new stats event.

func (StatsEvent) WriteJSON

func (se StatsEvent) WriteJSON() logger.JSONObj

WriteJSON implements logger.JSONWritable.

func (StatsEvent) WriteText

func (se StatsEvent) WriteText(tf logger.TextFormatter, buf *bytes.Buffer)

WriteText writes the event to a text writer.

type Step

type Step struct {
	// contains filtered or unexported fields
}

Step is a single guarded function.

func NewStep

func NewStep(guard GuardFunc, body InvocableFunc) *Step

NewStep is an alias to NewOperation.

func (*Step) Apply

func (s *Step) Apply(c *db.Connection, tx *sql.Tx) error

Apply applies a step in isolation.

func (*Step) Invoke

func (s *Step) Invoke(suite *Suite, group *Group, c *db.Connection, tx *sql.Tx) (err error)

Invoke runs the body if the provided guard passes.

func (*Step) Label

func (s *Step) Label() string

Label returns the operation label.

func (*Step) WithLabel

func (s *Step) WithLabel(label string) *Step

WithLabel sets the operation label.

type Suite

type Suite struct {
	// contains filtered or unexported fields
}

Suite is a migration suite.

func New

func New(groups ...*Group) *Suite

New returns a new suite of groups.

func (*Suite) Apply

func (s *Suite) Apply(c *db.Connection) (err error)

Apply applies the suite.

func (*Suite) Logger

func (s *Suite) Logger() *logger.Logger

Logger returns the underlying logger.

func (*Suite) WithGroups

func (s *Suite) WithGroups(groups ...*Group) *Suite

WithGroups adds groups to the suite and returns the suite.

func (*Suite) WithLogger

func (s *Suite) WithLogger(log *logger.Logger) *Suite

WithLogger sets the suite logger.

Directories

Path Synopsis
_examples
datafiles command

Jump to

Keyboard shortcuts

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