Documentation
¶
Index ¶
- Constants
- func NoOp(c *db.Connection, tx *sql.Tx) error
- type DataFileReader
- type Event
- type Group
- type GuardFunc
- func AlwaysRun() GuardFunc
- func ColumnExists(tableName, columnName string) GuardFunc
- func ColumnNotExists(tableName, columnName string) GuardFunc
- func ConstraintExists(constraintName string) GuardFunc
- func ConstraintNotExists(constraintName string) GuardFunc
- func Guard(description string, evaluator func(c *db.Connection, tx *sql.Tx) (bool, error)) GuardFunc
- func IfExists(statement string) GuardFunc
- func IfNotExists(statement string) GuardFunc
- func IndexExists(tableName, indexName string) GuardFunc
- func IndexNotExists(tableName, indexName string) GuardFunc
- func RoleExists(roleName string) GuardFunc
- func RoleNotExists(roleName string) GuardFunc
- func TableExists(tableName string) GuardFunc
- func TableNotExists(tableName string) GuardFunc
- type Invocable
- type InvocableFunc
- type StatsEvent
- type Step
- type Suite
Constants ¶
const ( // Flag is a logger event flag. Flag logger.Flag = "db.migration" // FlagStats is a logger event flag. FlagStats logger.Flag = "db.migration.stats" )
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 ¶
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 ¶
Event is a migration logger event.
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 (*Group) Invoke ¶
func (g *Group) Invoke(suite *Suite, c *db.Connection) (err error)
Invoke runs the steps in a transaction.
type GuardFunc ¶
GuardFunc is a control for migration steps.
func ColumnExists ¶
ColumnExists alters an existing column, erroring if it doesn't exist
func ColumnNotExists ¶
ColumnNotExists creates a table on the given connection if it does not exist.
func ConstraintExists ¶
ConstraintExists alters an existing constraint, erroring if it doesn't exist
func ConstraintNotExists ¶
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 IfNotExists ¶
IfNotExists only runs the statement if the given item doesn't exist.
func IndexExists ¶
IndexExists alters an existing index, erroring if it doesn't exist
func IndexNotExists ¶
IndexNotExists creates a index on the given connection if it does not exist.
func RoleExists ¶
RoleExists alters an existing role in the db
func RoleNotExists ¶
RoleNotExists creates a new role if it doesn't exist.
func TableExists ¶
TableExists alters an existing table, erroring if it doesn't exist
func TableNotExists ¶
TableNotExists creates a table on the given connection if it does not exist.
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 ¶
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.