Versions in this module Expand all Collapse all v3 v3.0.1 Nov 20, 2023 v3.0.0 Nov 20, 2023 Changes in this version + const DefaultTablename + const VERSION + var ErrAlreadyApplied = errors.New("already applied") + var ErrNoCurrentVersion = errors.New("no current version found") + var ErrNoMigrationFiles = errors.New("no migration files found") + var ErrNoMigrations = errors.New("no migrations found") + var ErrNoNextVersion = errors.New("no next version found") + var ErrVersionNotFound = errors.New("version not found") + var MaxVersion int64 = math.MaxInt64 + func AddMigration(up, down GoMigration) + func AddMigrationContext(up, down GoMigrationContext) + func AddMigrationNoTx(up, down GoMigrationNoTx) + func AddMigrationNoTxContext(up, down GoMigrationNoTxContext) + func AddNamedMigration(filename string, up, down GoMigration) + func AddNamedMigrationContext(filename string, up, down GoMigrationContext) + func AddNamedMigrationNoTx(filename string, up, down GoMigrationNoTx) + func AddNamedMigrationNoTxContext(filename string, up, down GoMigrationNoTxContext) + func Create(db *sql.DB, dir, name, migrationType string) error + func CreateWithTemplate(db *sql.DB, dir string, tmpl *template.Template, name, migrationType string) error + func Down(db *sql.DB, dir string, opts ...OptionsFunc) error + func DownContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error + func DownTo(db *sql.DB, dir string, version int64, opts ...OptionsFunc) error + func DownToContext(ctx context.Context, db *sql.DB, dir string, version int64, ...) error + func EnsureDBVersion(db *sql.DB) (int64, error) + func EnsureDBVersionContext(ctx context.Context, db *sql.DB) (int64, error) + func Fix(dir string) error + func GetDBVersion(db *sql.DB) (int64, error) + func GetDBVersionContext(ctx context.Context, db *sql.DB) (int64, error) + func NumericComponent(filename string) (int64, error) + func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error) + func Redo(db *sql.DB, dir string, opts ...OptionsFunc) error + func RedoContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error + func Reset(db *sql.DB, dir string, opts ...OptionsFunc) error + func ResetContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error + func ResetGlobalMigrations() + func Run(command string, db *sql.DB, dir string, args ...string) error + func RunContext(ctx context.Context, command string, db *sql.DB, dir string, args ...string) error + func RunWithOptions(command string, db *sql.DB, dir string, args []string, options ...OptionsFunc) error + func RunWithOptionsContext(ctx context.Context, command string, db *sql.DB, dir string, args []string, ...) error + func SetBaseFS(fsys fs.FS) + func SetDialect(s string) error + func SetGlobalMigrations(migrations ...*Migration) error + func SetLogger(l Logger) + func SetSequential(s bool) + func SetTableName(n string) + func SetVerbose(v bool) + func Status(db *sql.DB, dir string, opts ...OptionsFunc) error + func StatusContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error + func TableName() string + func Up(db *sql.DB, dir string, opts ...OptionsFunc) error + func UpByOne(db *sql.DB, dir string, opts ...OptionsFunc) error + func UpByOneContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error + func UpContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error + func UpTo(db *sql.DB, dir string, version int64, opts ...OptionsFunc) error + func UpToContext(ctx context.Context, db *sql.DB, dir string, version int64, ...) error + func Version(db *sql.DB, dir string, opts ...OptionsFunc) error + func VersionContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error + type Dialect = database.Dialect + const DialectClickHouse + const DialectMSSQL + const DialectMySQL + const DialectPostgres + const DialectRedshift + const DialectSQLAnywhere + const DialectSQLite3 + const DialectTiDB + const DialectVertica + const DialectYdB + type GoFunc struct + Mode TransactionMode + RunDB func(ctx context.Context, db *sql.DB) error + RunTx func(ctx context.Context, tx *sql.Tx) error + type GoMigration func(tx *sql.Tx) error + type GoMigrationContext func(ctx context.Context, tx *sql.Tx) error + type GoMigrationNoTx func(db *sql.DB) error + type GoMigrationNoTxContext func(ctx context.Context, db *sql.DB) error + type Logger interface + Fatalf func(format string, v ...interface{}) + Printf func(format string, v ...interface{}) + func NopLogger() Logger + type Migration struct + DownFn GoMigration + DownFnContext GoMigrationContext + DownFnNoTx GoMigrationNoTx + DownFnNoTxContext GoMigrationNoTxContext + Next int64 + Previous int64 + Registered bool + Source string + Type MigrationType + UpFn GoMigration + UpFnContext GoMigrationContext + UpFnNoTx GoMigrationNoTx + UpFnNoTxContext GoMigrationNoTxContext + UseTx bool + Version int64 + func NewGoMigration(version int64, up, down *GoFunc) *Migration + func (m *Migration) Down(db *sql.DB) error + func (m *Migration) DownContext(ctx context.Context, db *sql.DB) error + func (m *Migration) String() string + func (m *Migration) Up(db *sql.DB) error + func (m *Migration) UpContext(ctx context.Context, db *sql.DB) error + type MigrationRecord struct + IsApplied bool + TStamp time.Time + VersionID int64 + type MigrationResult struct + Direction string + Duration time.Duration + Empty bool + Error error + Source *Source + type MigrationStatus struct + AppliedAt time.Time + Source *Source + State State + type MigrationType string + const TypeGo + const TypeSQL + type Migrations []*Migration + func CollectMigrations(dirpath string, current, target int64) (Migrations, error) + func (ms Migrations) Current(current int64) (*Migration, error) + func (ms Migrations) Last() (*Migration, error) + func (ms Migrations) Len() int + func (ms Migrations) Less(i, j int) bool + func (ms Migrations) Next(current int64) (*Migration, error) + func (ms Migrations) Previous(current int64) (*Migration, error) + func (ms Migrations) String() string + func (ms Migrations) Swap(i, j int) + type OptionsFunc func(o *options) + func WithAllowMissing() OptionsFunc + func WithNoColor(b bool) OptionsFunc + func WithNoVersioning() OptionsFunc + type PartialError struct + Applied []*MigrationResult + Err error + Failed *MigrationResult + func (e *PartialError) Error() string + type Provider struct + func NewProvider(dialect Dialect, db *sql.DB, fsys fs.FS, opts ...ProviderOption) (*Provider, error) + func (p *Provider) ApplyVersion(ctx context.Context, version int64, direction bool) (*MigrationResult, error) + func (p *Provider) Close() error + func (p *Provider) Down(ctx context.Context) (*MigrationResult, error) + func (p *Provider) DownTo(ctx context.Context, version int64) ([]*MigrationResult, error) + func (p *Provider) GetDBVersion(ctx context.Context) (int64, error) + func (p *Provider) ListSources() []*Source + func (p *Provider) Ping(ctx context.Context) error + func (p *Provider) Status(ctx context.Context) ([]*MigrationStatus, error) + func (p *Provider) Up(ctx context.Context) ([]*MigrationResult, error) + func (p *Provider) UpByOne(ctx context.Context) (*MigrationResult, error) + func (p *Provider) UpTo(ctx context.Context, version int64) ([]*MigrationResult, error) + type ProviderOption interface + func WithAllowOutofOrder(b bool) ProviderOption + func WithDisableGlobalRegistry(b bool) ProviderOption + func WithDisableVersioning(b bool) ProviderOption + func WithExcludeNames(excludes []string) ProviderOption + func WithExcludeVersions(versions []int64) ProviderOption + func WithGoMigrations(migrations ...*Migration) ProviderOption + func WithSessionLocker(locker lock.SessionLocker) ProviderOption + func WithStore(store database.Store) ProviderOption + func WithVerbose(b bool) ProviderOption + type Source struct + Path string + Type MigrationType + Version int64 + type State string + const StateApplied + const StatePending + type TransactionMode int + const TransactionDisabled + const TransactionEnabled + func (m TransactionMode) String() string