Documentation
¶
Index ¶
- Constants
- func CopyIn(table string, columns ...string) string
- func Exists(c *db.Connection, tx *sql.Tx, selectStatement string) (bool, error)
- func GetContextLabels(ctx context.Context) []string
- func NoOp(ctx context.Context, c *db.Connection, tx *sql.Tx) error
- func Not(proceed bool, err error) (bool, error)
- func NotExists(c *db.Connection, tx *sql.Tx, selectStatement string) (bool, error)
- func PredicateColumnExists(c *db.Connection, tx *sql.Tx, tableName, columnName string) (bool, error)
- func PredicateConstraintExists(c *db.Connection, tx *sql.Tx, constraintName string) (bool, error)
- func PredicateIndexExists(c *db.Connection, tx *sql.Tx, tableName, indexName string) (bool, error)
- func PredicateRoleExists(c *db.Connection, tx *sql.Tx, roleName string) (bool, error)
- func PredicateTableExists(c *db.Connection, tx *sql.Tx, tableName string) (bool, error)
- func QuoteIdentifier(name string) string
- func WithLabel(ctx context.Context, label string) context.Context
- func WithSuite(ctx context.Context, suite *Suite) context.Context
- type Action
- type Actionable
- type DataFileReader
- type Event
- type GroupedActions
- type GuardFunc
- func Always() GuardFunc
- func ColumnExists(tableName, columnName string) GuardFunc
- func ColumnExistsWithPredicate(predicate Predicate2, tableName, columnName string) GuardFunc
- func ColumnNotExists(tableName, columnName string) GuardFunc
- func ColumnNotExistsWithPredicate(predicate Predicate2, tableName, columnName string) GuardFunc
- func ConstraintExists(constraintName string) GuardFunc
- func ConstraintExistsWithPredicate(predicate Predicate, constraintName string) GuardFunc
- func ConstraintNotExists(constraintName string) GuardFunc
- func ConstraintNotExistsWithPredicate(predicate Predicate, constraintName string) GuardFunc
- func Guard(description string, predicate 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 IndexExistsWithPredicate(predicate Predicate2, tableName, indexName string) GuardFunc
- func IndexNotExists(tableName, indexName string) GuardFunc
- func IndexNotExistsWithPredicate(predicate Predicate2, tableName, indexName string) GuardFunc
- func RoleExists(roleName string) GuardFunc
- func RoleExistsWithPredicate(predicate Predicate, roleName string) GuardFunc
- func RoleNotExists(roleName string) GuardFunc
- func RoleNotExistsWithPredicate(predicate Predicate, roleName string) GuardFunc
- func TableExists(tableName string) GuardFunc
- func TableExistsWithPredicate(predicate Predicate, tableName string) GuardFunc
- func TableNotExists(tableName string) GuardFunc
- func TableNotExistsWithPredicate(predicate Predicate, tableName string) GuardFunc
- type GuardedAction
- type Predicate
- type Predicate2
- type StatsEvent
- type Suite
- func (s *Suite) Apply(c *db.Connection) (err error)
- func (s *Suite) Applyf(ctx context.Context, format string, args ...interface{})
- func (s *Suite) Context() context.Context
- func (s *Suite) Error(ctx context.Context, err error) error
- func (s *Suite) Errorf(ctx context.Context, format string, args ...interface{})
- func (s *Suite) Logger() logger.Log
- func (s *Suite) Skipf(ctx context.Context, format string, args ...interface{})
- func (s *Suite) WithContext(ctx context.Context) *Suite
- func (s *Suite) WithGroups(groups ...GroupedActions) *Suite
- func (s *Suite) WithLogger(log logger.Log) *Suite
- func (s *Suite) Write(ctx context.Context, result, body string)
- func (s *Suite) WriteStats()
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 ¶
func CopyIn ¶
CopyIn creates a COPY FROM statement which can be prepared with Tx.Prepare(). The target table should be visible in search_path.
func GetContextLabels ¶ added in v1.20201204.1
GetContextLabels gets a group from a context as a value.
func PredicateColumnExists ¶ added in v1.20201204.1
func PredicateColumnExists(c *db.Connection, tx *sql.Tx, tableName, columnName string) (bool, error)
PredicateColumnExists returns if a column exists on a table on the given connection.
func PredicateConstraintExists ¶ added in v1.20201204.1
PredicateConstraintExists returns if a constraint exists on a table on the given connection.
func PredicateIndexExists ¶ added in v1.20201204.1
PredicateIndexExists returns if a index exists on a table on the given connection.
func PredicateRoleExists ¶ added in v1.20201204.1
PredicateRoleExists returns if a role exists or not.
func PredicateTableExists ¶ added in v1.20201204.1
PredicateTableExists returns if a table exists on the given connection.
func QuoteIdentifier ¶
QuoteIdentifier quotes an "identifier" (e.g. a table or a column name) to be used as part of an SQL statement. For example:
tblname := "my_table" data := "my_data" quoted := pq.QuoteIdentifier(tblname) err := db.Exec(fmt.Sprintf("INSERT INTO %s VALUES ($1)", quoted), data)
Any double quotes in name will be escaped. The quoted identifier will be case sensitive when used in a query. If the input string contains a zero byte, the result will be truncated immediately before it.
Types ¶
type Action ¶ added in v1.20201204.1
Action is a function that can be run during a migration step.
func Statements ¶
Statements returns a body func that executes the statments serially.
type Actionable ¶ added in v1.20201204.1
Actionable is a type that represents a migration action.
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) Action ¶
func (dfr *DataFileReader) Action(ctx context.Context, c *db.Connection, tx *sql.Tx) (err error)
Action applies the file reader.
func (*DataFileReader) Label ¶
func (dfr *DataFileReader) Label() string
Label returns the label for the data file reader.
type Event ¶
Event is a migration logger event.
type GroupedActions ¶
type GroupedActions []Actionable
GroupedActions is an atomic series of migration actions. It uses transactions to apply these actions as an atomic unit.
func Group ¶
func Group(actions ...Actionable) GroupedActions
Group creates a new GroupedActions from a given list of actionable.
func (GroupedActions) Action ¶
func (ga GroupedActions) Action(ctx context.Context, c *db.Connection) (err error)
Action runs the groups actions within 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 ColumnExistsWithPredicate ¶
func ColumnExistsWithPredicate(predicate Predicate2, tableName, columnName string) GuardFunc
ColumnExistsWithPredicate 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 ColumnNotExistsWithPredicate ¶
func ColumnNotExistsWithPredicate(predicate Predicate2, tableName, columnName string) GuardFunc
ColumnNotExistsWithPredicate 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 ConstraintExistsWithPredicate ¶
ConstraintExistsWithPredicate 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 ConstraintNotExistsWithPredicate ¶
ConstraintNotExistsWithPredicate creates a table on the given connection if it does not exist.
func Guard ¶
func Guard(description string, predicate 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 IndexExistsWithPredicate ¶
func IndexExistsWithPredicate(predicate Predicate2, tableName, indexName string) GuardFunc
IndexExistsWithPredicate 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 IndexNotExistsWithPredicate ¶
func IndexNotExistsWithPredicate(predicate Predicate2, tableName, indexName string) GuardFunc
IndexNotExistsWithPredicate creates a index on the given connection if it does not exist.
func RoleExists ¶
RoleExists alters an existing role in the db
func RoleExistsWithPredicate ¶
RoleExistsWithPredicate alters an existing role in the db
func RoleNotExists ¶
RoleNotExists creates a new role if it doesn't exist.
func RoleNotExistsWithPredicate ¶
RoleNotExistsWithPredicate creates a new role if it doesn't exist.
func TableExists ¶
TableExists alters an existing table, erroring if it doesn't exist
func TableExistsWithPredicate ¶
TableExistsWithPredicate 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.
func TableNotExistsWithPredicate ¶
TableNotExistsWithPredicate creates a table on the given connection if it does not exist.
type GuardedAction ¶
GuardedAction is a guarded actionable.
func Step ¶
func Step(guard GuardFunc, action Action) *GuardedAction
Step returns a new guarded actionable.
func (GuardedAction) Action ¶
func (ga GuardedAction) Action(ctx context.Context, c *db.Connection, tx *sql.Tx) error
Action runs the body if the provided guard passes.
type Predicate2 ¶
Predicate2 is a function that evaluates based on two string params.
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 Suite ¶
type Suite struct {
// contains filtered or unexported fields
}
Suite is a migration suite.
func GetContextSuite ¶ added in v1.20201204.1
GetContextSuite gets a suite from a context as a value.
func (*Suite) WithContext ¶
WithContext sets the suite context.
func (*Suite) WithGroups ¶
func (s *Suite) WithGroups(groups ...GroupedActions) *Suite
WithGroups adds groups to the suite and returns the suite.
func (*Suite) WithLogger ¶
WithLogger sets the suite logger.
func (*Suite) WriteStats ¶ added in v1.20201204.1
func (s *Suite) WriteStats()
WriteStats writes the stats if a logger is configured.