Documentation
¶
Index ¶
- Constants
- func GetContextLabels(ctx context.Context) []string
- func NoOp(_ context.Context, _ *db.Connection, _ *sql.Tx) error
- func Not(proceed bool, err error) (bool, error)
- func PredicateAny(ctx context.Context, c *db.Connection, tx *sql.Tx, selectStatement string, ...) (bool, error)
- func PredicateColumnExists(ctx context.Context, c *db.Connection, tx *sql.Tx, ...) (bool, error)
- func PredicateConstraintExists(ctx context.Context, c *db.Connection, tx *sql.Tx, ...) (bool, error)
- func PredicateIndexExists(ctx context.Context, c *db.Connection, tx *sql.Tx, tableName, indexName string) (bool, error)
- func PredicateNone(ctx context.Context, c *db.Connection, tx *sql.Tx, selectStatement string, ...) (bool, error)
- func PredicateRoleExists(ctx context.Context, c *db.Connection, tx *sql.Tx, roleName string) (bool, error)
- func PredicateTableExists(ctx context.Context, c *db.Connection, tx *sql.Tx, tableName string) (bool, error)
- func WithLabel(ctx context.Context, label string) context.Context
- func WithSuite(ctx context.Context, suite *Suite) context.Context
- type Action
- type ActionFunc
- type Event
- type Group
- type GroupOption
- type GuardFunc
- func Always() GuardFunc
- func ColumnExists(tableName, columnName string) GuardFunc
- func ColumnNotExists(tableName, columnName string) GuardFunc
- func ConstraintExists(tableName, constraintName string) GuardFunc
- func ConstraintNotExists(tableName, constraintName string) GuardFunc
- func Guard(description string, predicate GuardPredicateFunc) GuardFunc
- func IfExists(statement string, args ...interface{}) GuardFunc
- func IfNotExists(statement string, args ...interface{}) 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 GuardPredicateFunc
- type StatementSlice
- type StatsEvent
- type Step
- type Suite
- func (s *Suite) Apply(ctx context.Context, c *db.Connection) (err error)
- func (s *Suite) ApplyTx(ctx context.Context, c *db.Connection, tx *sql.Tx) (err error)
- func (s *Suite) Write(ctx context.Context, result, body string)
- func (s *Suite) WriteApplyf(ctx context.Context, format string, args ...interface{})
- func (s *Suite) WriteError(ctx context.Context, err error) error
- func (s *Suite) WriteErrorf(ctx context.Context, format string, args ...interface{})
- func (s *Suite) WriteSkipf(ctx context.Context, format string, args ...interface{})
- func (s *Suite) WriteStats(ctx context.Context)
- type SuiteOption
Constants ¶
const ( StatApplied = "applied" StatFailed = "failed" StatSkipped = "skipped" StatTotal = "total" )
Migration Stats
Variables ¶
This section is empty.
Functions ¶
func GetContextLabels ¶
GetContextLabels gets a group from a context as a value.
func PredicateAny ¶
func PredicateAny(ctx context.Context, c *db.Connection, tx *sql.Tx, selectStatement string, params ...interface{}) (bool, error)
PredicateAny returns if a statement has results.
func PredicateColumnExists ¶
func PredicateColumnExists(ctx context.Context, c *db.Connection, tx *sql.Tx, tableName, columnName string) (bool, error)
PredicateColumnExists returns if a column exists on a table in a specific schema on the given connection.
func PredicateConstraintExists ¶
func PredicateConstraintExists(ctx context.Context, c *db.Connection, tx *sql.Tx, tableName, constraintName string) (bool, error)
PredicateConstraintExists returns if a constraint exists on a table in a specific schema on the given connection.
func PredicateIndexExists ¶
func PredicateIndexExists(ctx context.Context, c *db.Connection, tx *sql.Tx, tableName, indexName string) (bool, error)
PredicateIndexExists returns if a index exists on a table in a specific schema on the given connection.
func PredicateNone ¶
func PredicateNone(ctx context.Context, c *db.Connection, tx *sql.Tx, selectStatement string, params ...interface{}) (bool, error)
PredicateNone returns if a statement doesnt have results.
func PredicateRoleExists ¶
func PredicateRoleExists(ctx context.Context, c *db.Connection, tx *sql.Tx, roleName string) (bool, error)
PredicateRoleExists returns if a role exists or not.
func PredicateTableExists ¶
func PredicateTableExists(ctx context.Context, c *db.Connection, tx *sql.Tx, tableName string) (bool, error)
PredicateTableExists returns if a table exists in a specific schema on the given connection.
Types ¶
type Action ¶
Action is a type that represents a migration action.
func Actions ¶
Actions creates an Action with a single body func that executes all the variadic argument actions serially
func Exec ¶
Exec creates an Action that will run a statement with a given set of arguments. It can be used in lieu of Statements, when parameterization is needed
func Statements ¶
Statements returns a body func that executes the statments serially.
type ActionFunc ¶
ActionFunc is a function that can be run during a migration step.
func (ActionFunc) Action ¶
func (a ActionFunc) Action(ctx context.Context, conn *db.Connection, tx *sql.Tx) error
Action implements actioner.
type Group ¶
Group is an series of migration actions. It uses normally transactions to apply these actions as an atomic unit, but this transaction can be bypassed by setting the SkipTransaction flag to true. This allows the use of CONCURRENT index creation and other operations that postgres will not allow within a transaction.
func NewGroup ¶
func NewGroup(options ...GroupOption) *Group
NewGroup creates a new Group from a given list of actionable.
func NewGroupWithAction ¶
func NewGroupWithAction(action Action, options ...GroupOption) *Group
NewGroupWithAction returns a new group with a single action.
func NewGroupWithStep ¶
func NewGroupWithStep(guard GuardFunc, action Action, options ...GroupOption) *Group
NewGroupWithStep returns a new group with a single step.
type GroupOption ¶
type GroupOption func(g *Group)
GroupOption is an option for migration Groups (Group)
func OptGroupActions ¶
func OptGroupActions(actions ...Action) GroupOption
OptGroupActions allows you to add actions to the NewGroup. If you want, multiple OptActions can be applied to the same NewGroup. They are additive.
func OptGroupSkipTransaction ¶
func OptGroupSkipTransaction() GroupOption
OptGroupSkipTransaction will allow this group to be run outside of a transaction. Use this to concurrently create indices and perform other actions that cannot be executed in a Tx
func OptGroupTx ¶
func OptGroupTx(tx *sql.Tx) GroupOption
OptGroupTx sets a transaction on the group.
type GuardFunc ¶
GuardFunc is a control for migration steps. It should internally evaluate if the action should be called. The action is typically given separately so these two components can be composed.
func ColumnExists ¶
ColumnExists returns a guard that ensures a column exists
func ColumnNotExists ¶
ColumnNotExists returns a guard that ensures a column does not exist
func ConstraintExists ¶
ConstraintExists returns a guard that ensures a constraint exists
func ConstraintNotExists ¶
ConstraintNotExists returns a guard that ensures a constraint does not exist
func Guard ¶
func Guard(description string, predicate GuardPredicateFunc) 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 returns a guard that ensures an index exists
func IndexNotExists ¶
IndexNotExists returns a guard that ensures an index does not exist
func RoleExists ¶
RoleExists returns a guard that ensures a role (user) exists
func RoleNotExists ¶
RoleNotExists returns a guard that ensures a role (user) does not exist
func TableExists ¶
TableExists returns a guard that ensures a table exists
func TableNotExists ¶
TableNotExists returns a guard that ensures a table does not exist
type GuardPredicateFunc ¶
GuardPredicateFunc is a function that can act as a guard
type StatementSlice ¶
type StatementSlice []string
StatementSlice is an array of strings.
func (StatementSlice) Action ¶
func (s StatementSlice) Action(ctx context.Context, c *db.Connection, tx *sql.Tx) (err error)
Action implements Action.
type StatsEvent ¶
type StatsEvent struct {
// 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) String ¶
func (se StatsEvent) String() string
WriteText writes the event to a text writer.
type Step ¶
Step is a guarded action. The GuardFunc will decide whether to execute this Action
type Suite ¶
type Suite struct { Groups []*Group Log db.Logger Stats struct { Applied int Skipped int Failed int Total int } }
Suite is a migration suite.
func GetContextSuite ¶
GetContextSuite gets a suite from a context as a value.
func NewWithActions ¶
NewWithActions returns a new suite, with a new group, made up of given actions.
func NewWithGroups ¶
NewWithGroups returns a new suite from a given list of groups.
func (*Suite) WriteApplyf ¶
WriteApplyf writes an applied step message.
func (*Suite) WriteError ¶
WriteError writes an error for a given step.
func (*Suite) WriteErrorf ¶
WriteErrorf writes an error for a given step.
func (*Suite) WriteSkipf ¶
WriteSkipf skips a given step.
func (*Suite) WriteStats ¶
WriteStats writes the stats if a logger is configured.
type SuiteOption ¶
type SuiteOption func(s *Suite)
SuiteOption is an option for migration Suites
func OptGroups ¶
func OptGroups(groups ...*Group) SuiteOption
OptGroups allows you to add groups to the Suite. If you want, multiple OptGroups can be applied to the same Suite. They are additive.