Documentation
¶
Index ¶
- Constants
- func Exec(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection) (int, error)
- func ExecMax(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, ...) (int, error)
- func ExecVersion(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, ...) (int, error)
- func SetDisableCreateTable(disable bool)
- func SetIgnoreUnknown(v bool)
- func SetTable(name string)
- type AssetMigrationSource
- type EmbedFileSystemMigrationSource
- type FileMigrationSource
- type HttpFileSystemMigrationSource
- type MemoryMigrationSource
- type Migration
- type MigrationDirection
- type MigrationRecord
- type MigrationSet
- func (ms MigrationSet) Exec(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection) (int, error)
- func (ms MigrationSet) ExecMax(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, ...) (int, error)
- func (ms MigrationSet) ExecVersion(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, ...) (int, error)
- func (ms MigrationSet) GetMigrationRecords(ctx context.Context, db *pgx.Conn) ([]*MigrationRecord, error)
- func (ms MigrationSet) PlanMigration(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, ...) ([]*PlannedMigration, error)
- func (ms MigrationSet) PlanMigrationToVersion(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, ...) ([]*PlannedMigration, error)
- type MigrationSource
- type PackrBox
- type PlanError
- type PlannedMigration
- func PlanMigration(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, ...) ([]*PlannedMigration, error)
- func PlanMigrationToVersion(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, ...) ([]*PlannedMigration, error)
- func ToCatchup(migrations, existingMigrations []*Migration, lastRun *Migration) []*PlannedMigration
- type TxError
Constants ¶
const DefaultMigrationTableName = "migration_info"
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
func Exec(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection) (int, error)
Execute a set of migrations
Returns the number of applied migrations.
func ExecMax ¶
func ExecMax(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, max int) (int, error)
Execute a set of migrations
Will apply at most `max` migrations. Pass 0 for no limit (or use Exec).
Returns the number of applied migrations.
func ExecVersion ¶
func ExecVersion(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, version int64) (int, error)
Execute a set of migrations
Will apply at the target `version` of migration. Cannot be a negative value.
Returns the number of applied migrations.
func SetDisableCreateTable ¶
func SetDisableCreateTable(disable bool)
SetDisableCreateTable sets the boolean to disable the creation of the migration table
func SetIgnoreUnknown ¶
func SetIgnoreUnknown(v bool)
SetIgnoreUnknown sets the flag that skips database check to see if there is a migration in the database that is not in migration source.
This should be used sparingly as it is removing a safety check.
Types ¶
type AssetMigrationSource ¶
type AssetMigrationSource struct { // Asset should return content of file in path if exists Asset func(path string) ([]byte, error) // AssetDir should return list of files in the path AssetDir func(path string) ([]string, error) // Path in the bindata to use. Dir string }
Migrations from a bindata asset set.
func (AssetMigrationSource) FindMigrations ¶
func (a AssetMigrationSource) FindMigrations() ([]*Migration, error)
type EmbedFileSystemMigrationSource ¶
func (EmbedFileSystemMigrationSource) FindMigrations ¶
func (f EmbedFileSystemMigrationSource) FindMigrations() ([]*Migration, error)
type FileMigrationSource ¶
type FileMigrationSource struct {
Dir string
}
A set of migrations loaded from a directory.
func (FileMigrationSource) FindMigrations ¶
func (f FileMigrationSource) FindMigrations() ([]*Migration, error)
type HttpFileSystemMigrationSource ¶
type HttpFileSystemMigrationSource struct {
FileSystem http.FileSystem
}
func (HttpFileSystemMigrationSource) FindMigrations ¶
func (f HttpFileSystemMigrationSource) FindMigrations() ([]*Migration, error)
type MemoryMigrationSource ¶
type MemoryMigrationSource struct {
Migrations []*Migration
}
A hardcoded set of migrations, in-memory.
func (MemoryMigrationSource) FindMigrations ¶
func (m MemoryMigrationSource) FindMigrations() ([]*Migration, error)
type Migration ¶
type Migration struct { Id string Up []string Down []string DisableTransactionUp bool DisableTransactionDown bool }
func ParseMigration ¶
func ParseMigration(id string, r io.ReadSeeker) (*Migration, error)
Migration parsing
func ToApply ¶
func ToApply(migrations []*Migration, current string, direction MigrationDirection) []*Migration
Filter a slice of migrations into ones that should be applied.
func (Migration) NumberPrefixMatches ¶
func (Migration) VersionInt ¶
type MigrationRecord ¶
func GetMigrationRecords ¶
func GetMigrationRecords(ctx context.Context, db *pgx.Conn) ([]*MigrationRecord, error)
type MigrationSet ¶
type MigrationSet struct { // TableName name of the table used to store migration info. TableName string // IgnoreUnknown skips the check to see if there is a migration // ran in the database that is not in MigrationSource. // // This should be used sparingly as it is removing a safety check. IgnoreUnknown bool // DisableCreateTable disable the creation of the migration table DisableCreateTable bool }
MigrationSet provides database parameters for a migration execution
func (MigrationSet) Exec ¶
func (ms MigrationSet) Exec(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection) (int, error)
Returns the number of applied migrations.
func (MigrationSet) ExecMax ¶
func (ms MigrationSet) ExecMax(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, max int) (int, error)
Returns the number of applied migrations.
func (MigrationSet) ExecVersion ¶
func (ms MigrationSet) ExecVersion(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, version int64) (int, error)
Returns the number of applied migrations.
func (MigrationSet) GetMigrationRecords ¶
func (ms MigrationSet) GetMigrationRecords(ctx context.Context, db *pgx.Conn) ([]*MigrationRecord, error)
func (MigrationSet) PlanMigration ¶
func (ms MigrationSet) PlanMigration(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, max int) ([]*PlannedMigration, error)
Plan a migration.
func (MigrationSet) PlanMigrationToVersion ¶
func (ms MigrationSet) PlanMigrationToVersion(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, version int64) ([]*PlannedMigration, error)
Plan a migration to version.
type MigrationSource ¶
type PackrBox ¶
Avoids pulling in the packr library for everyone, mimicks the bits of packr.Box that we need.
type PlanError ¶
PlanError happens where no migration plan could be created between the sets of already applied migrations and the currently found. For example, when the database contains a migration which is not among the migrations list found for an operation.
type PlannedMigration ¶
func PlanMigration ¶
func PlanMigration(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, max int) ([]*PlannedMigration, error)
Plan a migration.
func PlanMigrationToVersion ¶
func PlanMigrationToVersion(ctx context.Context, db *pgx.Conn, m MigrationSource, dir MigrationDirection, version int64) ([]*PlannedMigration, error)
Plan a migration to version.
func ToCatchup ¶
func ToCatchup(migrations, existingMigrations []*Migration, lastRun *Migration) []*PlannedMigration