Documentation ¶
Overview ¶
Package migrate provides functionality for applying database migrations.
Index ¶
Constants ¶
const MigrationsNoLimit = 0
MigrationsNoLimit contains a special value that will not limit the number of migrations to apply.
const MigrationsTableName = "migrations"
MigrationsTableName contains name of table in a database that stores applied migrations.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppliedMigration ¶
AppliedMigration represent a single already applied migration.
type CustomMigration ¶
type CustomMigration struct {
// contains filtered or unexported fields
}
CustomMigration represents simplified but customizable migration
func NewCustomMigration ¶
func NewCustomMigration(id string, upSQL, downSQL []string, upFn, downFn func(tx *sql.Tx) error) *CustomMigration
NewCustomMigration creates simplified but customizable migration.
func (*CustomMigration) DownFn ¶
func (m *CustomMigration) DownFn() func(tx *sql.Tx) error
DownFn returns a function that will be called during rolling back the migration
func (*CustomMigration) DownSQL ¶
func (m *CustomMigration) DownSQL() []string
DownSQL returns a slice of SQL statements that will be executed during rolling back the migration.
func (*CustomMigration) UpFn ¶
func (m *CustomMigration) UpFn() func(tx *sql.Tx) error
UpFn returns a function that will be called during applying the migration
func (*CustomMigration) UpSQL ¶
func (m *CustomMigration) UpSQL() []string
UpSQL returns a slice of SQL statements that will be executed during applying the migration.
type Migration ¶
type Migration interface { ID() string UpSQL() []string DownSQL() []string UpFn() func(tx *sql.Tx) error // Not supported yet. DownFn() func(tx *sql.Tx) error // Not supported yet. }
Migration is an interface for all database migrations. Migration may implement RawMigrator interface for full control. Migration may implement TxDisabler interface to control transactions.
type MigrationStatus ¶
type MigrationStatus struct {
AppliedMigrations []AppliedMigration
}
MigrationStatus is the migration status.
func (*MigrationStatus) LastAppliedMigration ¶
func (ms *MigrationStatus) LastAppliedMigration() (appliedMig AppliedMigration, exist bool)
LastAppliedMigration returns last applied migration if it exists.
type MigrationsDirection ¶
type MigrationsDirection string
MigrationsDirection defines possible values for direction of database migrations.
const ( MigrationsDirectionUp MigrationsDirection = "up" MigrationsDirectionDown MigrationsDirection = "down" )
Directions of database migrations.
type MigrationsManager ¶
type MigrationsManager struct { Dialect dbkit.Dialect // contains filtered or unexported fields }
MigrationsManager is an object for running migrations.
func NewMigrationsManager ¶
func NewMigrationsManager(dbConn *sql.DB, dialect dbkit.Dialect, logger log.FieldLogger) (*MigrationsManager, error)
NewMigrationsManager creates a new MigrationsManager.
func NewMigrationsManagerWithOpts ¶
func NewMigrationsManagerWithOpts( dbConn *sql.DB, dialect dbkit.Dialect, logger log.FieldLogger, opts MigrationsManagerOpts, ) (*MigrationsManager, error)
NewMigrationsManagerWithOpts creates a new MigrationsManager with custom options
func (*MigrationsManager) Run ¶
func (mm *MigrationsManager) Run(migrations []Migration, direction MigrationsDirection) error
Run runs all passed migrations.
func (*MigrationsManager) RunLimit ¶
func (mm *MigrationsManager) RunLimit(migrations []Migration, direction MigrationsDirection, limit int) error
RunLimit runs at most `limit` migrations. Pass 0 (or MigrationsNoLimit const) for no limit (or use Run).
func (*MigrationsManager) Status ¶
func (mm *MigrationsManager) Status() (MigrationStatus, error)
Status returns the current migration status.
type MigrationsManagerOpts ¶
type MigrationsManagerOpts struct {
TableName string
}
MigrationsManagerOpts holds the Migration Manager options to be used in NewMigrationsManagerWithOpts
type NullMigration ¶
type NullMigration struct {
Dialect dbkit.Dialect
}
NullMigration represents an empty basic migration that may be embedded in regular migrations in order to write less code for satisfying the Migration interface.
func (*NullMigration) DownFn ¶
func (m *NullMigration) DownFn() func(tx *sql.Tx) error
DownFn is a stub that returns an empty function that implied to be called during rolling back the migration.
func (*NullMigration) DownSQL ¶
func (m *NullMigration) DownSQL() []string
DownSQL is a stub that returns an empty slice of SQL statements that implied to be executed during rolling back the migration.
func (*NullMigration) ID ¶
func (m *NullMigration) ID() string
ID is a stub that returns empty migration identifier.
func (*NullMigration) UpFn ¶
func (m *NullMigration) UpFn() func(tx *sql.Tx) error
UpFn is a stub that returns an empty function that implied to be called during applying the migration.
func (*NullMigration) UpSQL ¶
func (m *NullMigration) UpSQL() []string
UpSQL is a stub that returns an empty slice of SQL statements that implied to be executed during applying the migration.
type RawMigrator ¶
RawMigrator is an interface which allows overwrite default generate mechanism for full control on migrations. Uses sql-migrate migration structure.
type TxDisabler ¶
type TxDisabler interface {
DisableTx() bool
}
TxDisabler is an interface for Migration for controlling transaction