Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterDefault(m ...Migration) error
- func SetDefault(group *Group)
- type Collector
- type DataFileReader
- func (dfr *DataFileReader) Apply(c *db.Connection, optionalTx ...*sql.Tx) (err error)
- func (dfr *DataFileReader) Collector() *Collector
- func (dfr *DataFileReader) Invoke(c *db.Connection, tx *sql.Tx) (err error)
- func (dfr *DataFileReader) Label() string
- func (dfr *DataFileReader) Parent() Migration
- func (dfr *DataFileReader) TransactionBound() bool
- func (dfr *DataFileReader) WithCollector(collector *Collector) Migration
- func (dfr *DataFileReader) WithLabel(value string) Migration
- func (dfr *DataFileReader) WithParent(parent Migration) Migration
- func (dfr *DataFileReader) WithTransactionBound(transactionBound bool) Migration
- type Event
- type Group
- func (g *Group) AbortOnError() bool
- func (g *Group) Add(migrations ...Migration)
- func (g *Group) Apply(c *db.Connection, txs ...*sql.Tx) (err error)
- func (g *Group) Collector() *Collector
- func (g *Group) IsRoot() bool
- func (g *Group) Label() string
- func (g *Group) Parent() Migration
- func (g *Group) RollbackOnComplete() bool
- func (g *Group) TransactionBound() bool
- func (g *Group) UseTransaction() bool
- func (g *Group) With(migrations ...Migration) *Group
- func (g *Group) WithAbortOnError(value bool) *Group
- func (g *Group) WithCollector(collector *Collector) Migration
- func (g *Group) WithLabel(value string) Migration
- func (g *Group) WithLogger(log *logger.Logger) *Group
- func (g *Group) WithParent(parent Migration) Migration
- func (g *Group) WithRollbackOnComplete(rollbackOnComplete bool) *Group
- func (g *Group) WithUseTransaction(useTransaction bool) Migration
- type Guard
- func AlwaysRun() Guard
- func ColumnExists(tableName, columnName string) Guard
- func ColumnNotExists(tableName, columnName string) Guard
- func ConstraintExists(constraintName string) Guard
- func ConstraintNotExists(constraintName string) Guard
- func DynamicGuard(label string, guard func(c *db.Connection, tx *sql.Tx) (bool, error)) Guard
- func IfExists(statement string) Guard
- func IfNotExists(statement string) Guard
- func IndexExists(tableName, indexName string) Guard
- func IndexNotExists(tableName, indexName string) Guard
- func RoleExists(roleName string) Guard
- func RoleNotExists(roleName string) Guard
- func TableExists(tableName string) Guard
- func TableNotExists(tableName string) Guard
- type Invocable
- type InvocableAction
- type Migration
- type StatsEvent
- type Step
- func (s *Step) Apply(c *db.Connection, txs ...*sql.Tx) (err error)
- func (s *Step) Collector() *Collector
- func (s *Step) Label() string
- func (s *Step) Parent() Migration
- func (s *Step) TransactionBound() bool
- func (s *Step) WithCollector(collector *Collector) Migration
- func (s *Step) WithLabel(label string) Migration
- func (s *Step) WithParent(parent Migration) Migration
- func (s *Step) WithTransactionBound(transactionBound bool) Migration
Constants ¶
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" )
const ( // Flag is a logger event flag. Flag logger.Flag = "db.migration" // FlagStats is a logger event flag. FlagStats logger.Flag = "db.migration.stats" )
Variables ¶
var (
// NoOp is used when testing guards.
NoOp = noOp{}
)
Functions ¶
func RegisterDefault ¶
RegisterDefault adds migrations to the default group.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector is a results collector.
func (*Collector) WriteStats ¶
func (c *Collector) WriteStats()
WriteStats writes final stats to output
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, optionalTx ...*sql.Tx) (err error)
Apply applies the data file reader.
func (*DataFileReader) Collector ¶
func (dfr *DataFileReader) Collector() *Collector
Collector returns the logger.
func (*DataFileReader) Invoke ¶
func (dfr *DataFileReader) Invoke(c *db.Connection, tx *sql.Tx) (err error)
Invoke consumes the data file and writes it to the db.
func (*DataFileReader) Label ¶
func (dfr *DataFileReader) Label() string
Label returns the label for the data file reader.
func (*DataFileReader) Parent ¶
func (dfr *DataFileReader) Parent() Migration
Parent returns the parent for the data file reader.
func (*DataFileReader) TransactionBound ¶
func (dfr *DataFileReader) TransactionBound() bool
TransactionBound returns if the migration manages its own transactions.
func (*DataFileReader) WithCollector ¶
func (dfr *DataFileReader) WithCollector(collector *Collector) Migration
WithCollector sets the logger for the data file reader.
func (*DataFileReader) WithLabel ¶
func (dfr *DataFileReader) WithLabel(value string) Migration
WithLabel sets the migration label.
func (*DataFileReader) WithParent ¶
func (dfr *DataFileReader) WithParent(parent Migration) Migration
WithParent sets the parent for the data file reader.
func (*DataFileReader) WithTransactionBound ¶
func (dfr *DataFileReader) WithTransactionBound(transactionBound bool) Migration
WithTransactionBound sets if the migration manages its own transactions or not.
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) AbortOnError ¶
AbortOnError indicates that the group will abort if it sees an error from a step.
func (*Group) Apply ¶
Apply wraps the action in a transaction and commits it if there were no errors, rolling back if there were.
func (*Group) RollbackOnComplete ¶
RollbackOnComplete returns if we should rollback the migration on complete.
func (*Group) TransactionBound ¶
TransactionBound returns if the migration manages its own transactions. This is a group, it is the one doing the managing.
func (*Group) UseTransaction ¶
UseTransaction returns if the group should wrap child steps in a transaction.
func (*Group) WithAbortOnError ¶
WithAbortOnError sets if the group should abort on error.
func (*Group) WithCollector ¶
WithCollector sets the collector.
func (*Group) WithLogger ¶
WithLogger sets the collector output logger.
func (*Group) WithParent ¶
WithParent sets the runner's parent.
func (*Group) WithRollbackOnComplete ¶
WithRollbackOnComplete sets if we should roll the transaction back on complete.
func (*Group) WithUseTransaction ¶
WithUseTransaction sets if we should begin a transaction for the work within the group.
type Guard ¶
Guard 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 DynamicGuard ¶
DynamicGuard is guard that can dynamically determine if the inner invocable 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 Invocable ¶
type Invocable interface {
Invoke(c *db.Connection, tx *sql.Tx) error
}
Invocable is a thing that can be invoked.
func Actions ¶
func Actions(invocableActions ...InvocableAction) Invocable
Actions returns an invocable of a set of actions.
func Statements ¶
Statements is an alias to Body(...Statement(stmt))
type InvocableAction ¶
type InvocableAction func(c *db.Connection, tx *sql.Tx) error
InvocableAction is a function that can be run during a migration step.
type Migration ¶
type Migration interface {
WithLabel(label string) Migration
Label() string
WithParent(parent Migration) Migration
Parent() Migration
WithCollector(*Collector) Migration
Collector() *Collector
// TransactionBound indicates if this migration manages its transaction context.
// If this returns true, a parent will not pass a transaction into Apply.
// If it is false, a transaction will be started for this
TransactionBound() bool
// Apply runs the migration.
Apply(c *db.Connection, txs ...*sql.Tx) error
}
Migration is either a group of steps or the entire suite.
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 (*Step) Apply ¶
Apply wraps the action in a transaction and commits it if there were no errors, rolling back if there were.
func (*Step) TransactionBound ¶
TransactionBound returns if the migration manages its own transactions.
func (*Step) WithCollector ¶
WithCollector sets the collector.
func (*Step) WithParent ¶
WithParent sets the operation parent.
func (*Step) WithTransactionBound ¶
WithTransactionBound sets if the migration manages its own transactions or not.