Documentation
¶
Index ¶
- Constants
- Variables
- func GetConnection(ctx context.Context, connection *pop.Connection) *pop.Connection
- func Identifier(i string) (string, error)
- func MigrateSQLDown(cmd *cobra.Command, p MigrationProvider) (err error)
- func MigrateSQLUp(cmd *cobra.Command, p MigrationProvider) (err error)
- func MigrateStatus(cmd *cobra.Command, p MigrationProvider) (err error)
- func NewMigrateSQLDownCmd(binaryName string, runE func(cmd *cobra.Command, args []string) error) *cobra.Command
- func NewMigrateSQLStatusCmd(binaryName string, runE func(cmd *cobra.Command, args []string) error) *cobra.Command
- func NewMigrateSQLUpCmd(binaryName string, runE func(cmd *cobra.Command, args []string) error) *cobra.Command
- func NullLogger() func(lvl logging.Level, s string, args ...interface{})
- func ParameterizedMigrationContent(params map[string]interface{}) ...
- func RegisterMigrateSQLDownFlags(cmd *cobra.Command) *cobra.Command
- func RegisterMigrateSQLUpFlags(cmd *cobra.Command) *cobra.Command
- func RegisterMigrateStatusFlags(cmd *cobra.Command) *cobra.Command
- func TestingLogger(t testing.TB) func(lvl logging.Level, s string, args ...interface{})
- func Transaction(ctx context.Context, connection *pop.Connection, ...) error
- func WithTransaction(ctx context.Context, tx *pop.Connection) context.Context
- func WithWriteContents() func(*writeOptions)
- type Match
- type Migration
- type MigrationBox
- type MigrationBoxOption
- func WithGoMigrations(migrations Migrations) MigrationBoxOption
- func WithMigrationContentMiddleware(middleware func(content string, err error) (string, error)) MigrationBoxOption
- func WithTemplateValues(v map[string]interface{}) MigrationBoxOption
- func WithTestdata(t *testing.T, testdata fs.FS) MigrationBoxOption
- type MigrationContent
- type MigrationPreparer
- type MigrationProvider
- type MigrationStatus
- type MigrationStatuses
- func (m MigrationStatuses) HasPending() bool
- func (m MigrationStatuses) Header() []string
- func (m MigrationStatuses) IDs() []string
- func (m MigrationStatuses) Interface() interface{}
- func (m MigrationStatuses) Len() int
- func (m MigrationStatuses) Table() [][]string
- func (m MigrationStatuses) Write(out io.Writer, opts ...func(*writeOptions)) error
- type Migrations
- type Migrator
- func (m *Migrator) CreateSchemaMigrations(ctx context.Context) error
- func (m *Migrator) Down(ctx context.Context, steps int) error
- func (m *Migrator) DumpMigrationSchema(ctx context.Context) error
- func (m *Migrator) MigrationIsCompatible(dialect string, mi Migration) bool
- func (m *Migrator) Reset(ctx context.Context) error
- func (m *Migrator) Status(ctx context.Context) (MigrationStatuses, error)
- func (m *Migrator) Up(ctx context.Context) error
- func (m *Migrator) UpTo(ctx context.Context, step int) (applied int, err error)
- type TestMigrator
Constants ¶
const ( Pending = "Pending" Applied = "Applied" )
const ( MigrationStatusOpName = "migration-status" MigrationInitOpName = "migration-init" MigrationUpOpName = "migration-up" MigrationRunTransactionOpName = "migration-run-transaction" MigrationDownOpName = "migration-down" )
Variables ¶
var SQLTemplateFuncs = map[string]interface{}{ "identifier": Identifier, }
var (
TransactionRetries prometheus.Collector = transactionRetries
)
Functions ¶
func GetConnection ¶ added in v0.0.228
func GetConnection(ctx context.Context, connection *pop.Connection) *pop.Connection
func Identifier ¶ added in v0.0.300
func MigrateSQLDown ¶ added in v0.0.671
func MigrateSQLDown(cmd *cobra.Command, p MigrationProvider) (err error)
func MigrateSQLUp ¶ added in v0.0.671
func MigrateSQLUp(cmd *cobra.Command, p MigrationProvider) (err error)
func MigrateStatus ¶ added in v0.0.671
func MigrateStatus(cmd *cobra.Command, p MigrationProvider) (err error)
func NewMigrateSQLDownCmd ¶ added in v0.0.673
func NewMigrateSQLStatusCmd ¶ added in v0.0.674
func NewMigrateSQLUpCmd ¶ added in v0.0.674
func NullLogger ¶ added in v0.0.634
func ParameterizedMigrationContent ¶ added in v0.0.185
func RegisterMigrateSQLDownFlags ¶ added in v0.0.671
func RegisterMigrateSQLUpFlags ¶ added in v0.0.671
func RegisterMigrateStatusFlags ¶ added in v0.0.671
func TestingLogger ¶ added in v0.0.634
func Transaction ¶ added in v0.0.228
func Transaction(ctx context.Context, connection *pop.Connection, callback func(context.Context, *pop.Connection) error) error
func WithTransaction ¶ added in v0.0.228
func WithWriteContents ¶ added in v0.0.671
func WithWriteContents() func(*writeOptions)
Types ¶
type Match ¶ added in v0.0.665
type Match struct {
Version string
Name string
DBType string
Direction string
Type string
Autocommit bool
}
Match holds the information parsed from a migration filename.
func ParseMigrationFilename ¶ added in v0.0.665
ParseMigrationFilename parses a migration filename.
type Migration ¶ added in v0.0.185
type Migration struct {
// Path to the migration (./migrations/123_create_widgets.up.sql)
Path string
// Version of the migration (123)
Version string
// Name of the migration (create_widgets)
Name string
// Direction of the migration (up|down)
Direction string
// Type of migration (sql|go)
Type string
// DB type (all|postgres|mysql...)
DBType string
// Runner function to run/execute the migration. Will be wrapped in a
// database transaction. Mutually exclusive with RunnerNoTx
Runner func(Migration, *pop.Connection, *pop.Tx) error
// RunnerNoTx function to run/execute the migration. NOT wrapped in a
// database transaction. Mutually exclusive with Runner.
RunnerNoTx func(Migration, *pop.Connection) error
// Content is the raw content of the migration file
Content string
// Autocommit is true if the migration should be run outside of a transaction
Autocommit bool
}
Migration handles the data for a given database migration
type MigrationBox ¶ added in v0.0.190
MigrationBox is a embed migration box.
func NewMigrationBox ¶ added in v0.0.190
func NewMigrationBox(dir fs.FS, m *Migrator, opts ...MigrationBoxOption) (*MigrationBox, error)
NewMigrationBox creates a new migration box.
type MigrationBoxOption ¶ added in v0.0.461
type MigrationBoxOption func(*MigrationBox) *MigrationBox
func WithGoMigrations ¶ added in v0.0.347
func WithGoMigrations(migrations Migrations) MigrationBoxOption
WithGoMigrations adds migrations that have a custom migration runner. TEST THEM THOROUGHLY! It will be very hard to fix a buggy migration.
func WithMigrationContentMiddleware ¶ added in v0.0.183
func WithMigrationContentMiddleware(middleware func(content string, err error) (string, error)) MigrationBoxOption
func WithTemplateValues ¶ added in v0.0.183
func WithTemplateValues(v map[string]interface{}) MigrationBoxOption
func WithTestdata ¶ added in v0.0.388
func WithTestdata(t *testing.T, testdata fs.FS) MigrationBoxOption
WithTestdata adds testdata to the migration box.
type MigrationContent ¶ added in v0.0.183
type MigrationPreparer ¶ added in v0.0.671
type MigrationProvider ¶ added in v0.0.671
type MigrationStatus ¶ added in v0.0.185
type MigrationStatuses ¶ added in v0.0.185
type MigrationStatuses []MigrationStatus
func (MigrationStatuses) HasPending ¶ added in v0.0.185
func (m MigrationStatuses) HasPending() bool
func (MigrationStatuses) Header ¶ added in v0.0.199
func (m MigrationStatuses) Header() []string
func (MigrationStatuses) IDs ¶ added in v0.0.199
func (m MigrationStatuses) IDs() []string
func (MigrationStatuses) Interface ¶ added in v0.0.199
func (m MigrationStatuses) Interface() interface{}
func (MigrationStatuses) Len ¶ added in v0.0.199
func (m MigrationStatuses) Len() int
func (MigrationStatuses) Table ¶ added in v0.0.199
func (m MigrationStatuses) Table() [][]string
type Migrations ¶ added in v0.0.185
type Migrations []Migration
Migrations is a collection of Migration
func (Migrations) Len ¶ added in v0.0.185
func (mfs Migrations) Len() int
func (Migrations) Less ¶ added in v0.0.185
func (mfs Migrations) Less(i, j int) bool
func (Migrations) SortAndFilter ¶ added in v0.0.201
func (mfs Migrations) SortAndFilter(dialect string, modifiers ...func(sort.Interface) sort.Interface) Migrations
func (Migrations) Swap ¶ added in v0.0.185
func (mfs Migrations) Swap(i, j int)
type Migrator ¶ added in v0.0.183
type Migrator struct {
Connection *pop.Connection
Migrations map[string]Migrations
PerMigrationTimeout time.Duration
// DumpMigrations if true will dump the migrations to a file called schema.sql
DumpMigrations bool
// contains filtered or unexported fields
}
Migrator forms the basis of all migrations systems. It does the actual heavy lifting of running migrations. When building a new migration system, you should embed this type into your migrator.
func NewMigrator ¶ added in v0.0.183
func NewMigrator(c *pop.Connection, l *logrusx.Logger, tracer *otelx.Tracer, perMigrationTimeout time.Duration) *Migrator
NewMigrator returns a new "blank" migrator. It is recommended to use something like MigrationBox or FileMigrator. A "blank" Migrator should only be used as the basis for a new type of migration system.
func (*Migrator) CreateSchemaMigrations ¶ added in v0.0.183
CreateSchemaMigrations sets up a table to track migrations. This is an idempotent operation.
func (*Migrator) Down ¶ added in v0.0.183
Down runs pending "down" migrations and rolls back the database by the specified number of steps.
func (*Migrator) DumpMigrationSchema ¶ added in v0.0.183
DumpMigrationSchema will generate a file of the current database schema
func (*Migrator) MigrationIsCompatible ¶ added in v0.0.185
MigrationIsCompatible returns true if the migration is compatible with the current database.
func (*Migrator) Reset ¶ added in v0.0.183
Reset the database by running the down migrations followed by the up migrations.
func (*Migrator) Status ¶ added in v0.0.183
func (m *Migrator) Status(ctx context.Context) (MigrationStatuses, error)
Status prints out the status of applied/pending migrations.
type TestMigrator ¶
type TestMigrator struct {
*Migrator
}
TestMigrator is a modified pop.FileMigrator
func NewTestMigrator ¶
func NewTestMigrator(t *testing.T, c *pop.Connection, migrations, testData fs.FS, l *logrusx.Logger) *TestMigrator
NewTestMigrator returns a new TestMigrator After running each migration it applies it's corresponding testData sql files. They are identified by having the same version (= number in the front of the filename). The filenames are expected to be of the format ([0-9]+).*(_testdata(\.[dbtype])?.sql