Documentation ¶
Index ¶
- func Exec(ctx context.Context, db *bun.DB, f io.Reader, isTx bool) error
- type GoMigrationOption
- type Migration
- type MigrationFile
- type MigrationFunc
- type MigrationGroup
- type MigrationOption
- type MigrationSlice
- type Migrations
- func (m *Migrations) Add(migration Migration)
- func (m *Migrations) Discover(fsys fs.FS) error
- func (m *Migrations) DiscoverCaller() error
- func (m *Migrations) MustRegister(up, down MigrationFunc)
- func (m *Migrations) Register(up, down MigrationFunc) error
- func (m *Migrations) Sorted() MigrationSlice
- type MigrationsOption
- type Migrator
- func (m *Migrator) AppliedMigrations(ctx context.Context) (MigrationSlice, error)
- func (m *Migrator) CreateGoMigration(ctx context.Context, name string, opts ...GoMigrationOption) (*MigrationFile, error)
- func (m *Migrator) CreateSQLMigrations(ctx context.Context, name string) ([]*MigrationFile, error)
- func (m *Migrator) CreateTxSQLMigrations(ctx context.Context, name string) ([]*MigrationFile, error)
- func (m *Migrator) DB() *bun.DB
- func (m *Migrator) Init(ctx context.Context) error
- func (m *Migrator) Lock(ctx context.Context) error
- func (m *Migrator) MarkApplied(ctx context.Context, migration *Migration) error
- func (m *Migrator) MarkUnapplied(ctx context.Context, migration *Migration) error
- func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*MigrationGroup, error)
- func (m *Migrator) MigrationsWithStatus(ctx context.Context) (MigrationSlice, error)
- func (m *Migrator) MissingMigrations(ctx context.Context) (MigrationSlice, error)
- func (m *Migrator) Reset(ctx context.Context) error
- func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*MigrationGroup, error)
- func (m *Migrator) TruncateTable(ctx context.Context) error
- func (m *Migrator) Unlock(ctx context.Context) error
- type MigratorOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type GoMigrationOption ¶
type GoMigrationOption func(cfg *goMigrationConfig)
func WithGoTemplate ¶
func WithGoTemplate(template string) GoMigrationOption
func WithPackageName ¶
func WithPackageName(name string) GoMigrationOption
type Migration ¶
type Migration struct { bun.BaseModel ID int64 `bun:",pk,autoincrement"` Name string Comment string `bun:"-"` GroupID int64 MigratedAt time.Time `bun:",notnull,nullzero,default:current_timestamp"` Up MigrationFunc `bun:"-"` Down MigrationFunc `bun:"-"` }
type MigrationFile ¶
type MigrationFunc ¶
func NewSQLMigrationFunc ¶
func NewSQLMigrationFunc(fsys fs.FS, name string) MigrationFunc
type MigrationGroup ¶
type MigrationGroup struct { ID int64 Migrations MigrationSlice }
func (MigrationGroup) IsZero ¶
func (g MigrationGroup) IsZero() bool
func (MigrationGroup) String ¶
func (g MigrationGroup) String() string
type MigrationOption ¶
type MigrationOption func(cfg *migrationConfig)
func WithNopMigration ¶
func WithNopMigration() MigrationOption
type MigrationSlice ¶
type MigrationSlice []Migration
func (MigrationSlice) Applied ¶
func (ms MigrationSlice) Applied() MigrationSlice
Applied returns applied migrations in descending order (the order is important and is used in Rollback).
func (MigrationSlice) LastGroup ¶
func (ms MigrationSlice) LastGroup() *MigrationGroup
LastGroup returns the last applied migration group.
func (MigrationSlice) LastGroupID ¶
func (ms MigrationSlice) LastGroupID() int64
LastGroupID returns the last applied migration group id. The id is 0 when there are no migration groups.
func (MigrationSlice) String ¶
func (ms MigrationSlice) String() string
func (MigrationSlice) Unapplied ¶
func (ms MigrationSlice) Unapplied() MigrationSlice
Unapplied returns unapplied migrations in ascending order (the order is important and is used in Migrate).
type Migrations ¶
type Migrations struct {
// contains filtered or unexported fields
}
func NewMigrations ¶
func NewMigrations(opts ...MigrationsOption) *Migrations
func (*Migrations) Add ¶
func (m *Migrations) Add(migration Migration)
func (*Migrations) DiscoverCaller ¶
func (m *Migrations) DiscoverCaller() error
func (*Migrations) MustRegister ¶
func (m *Migrations) MustRegister(up, down MigrationFunc)
func (*Migrations) Register ¶
func (m *Migrations) Register(up, down MigrationFunc) error
func (*Migrations) Sorted ¶
func (m *Migrations) Sorted() MigrationSlice
type MigrationsOption ¶
type MigrationsOption func(m *Migrations)
func WithMigrationsDirectory ¶
func WithMigrationsDirectory(directory string) MigrationsOption
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
func NewMigrator ¶
func NewMigrator(db *bun.DB, migrations *Migrations, opts ...MigratorOption) *Migrator
func (*Migrator) AppliedMigrations ¶
func (m *Migrator) AppliedMigrations(ctx context.Context) (MigrationSlice, error)
AppliedMigrations selects applied (applied) migrations in descending order.
func (*Migrator) CreateGoMigration ¶
func (m *Migrator) CreateGoMigration( ctx context.Context, name string, opts ...GoMigrationOption, ) (*MigrationFile, error)
CreateGoMigration creates a Go migration file.
func (*Migrator) CreateSQLMigrations ¶
CreateSQLMigrations creates up and down SQL migration files.
func (*Migrator) CreateTxSQLMigrations ¶
func (m *Migrator) CreateTxSQLMigrations(ctx context.Context, name string) ([]*MigrationFile, error)
CreateTxSQLMigration creates transactional up and down SQL migration files.
func (*Migrator) MarkApplied ¶
MarkApplied marks the migration as applied (completed).
func (*Migrator) MarkUnapplied ¶
MarkUnapplied marks the migration as unapplied (new).
func (*Migrator) Migrate ¶
func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*MigrationGroup, error)
Migrate runs unapplied migrations. If a migration fails, migrate immediately exits.
func (*Migrator) MigrationsWithStatus ¶
func (m *Migrator) MigrationsWithStatus(ctx context.Context) (MigrationSlice, error)
MigrationsWithStatus returns migrations with status in ascending order.
func (*Migrator) MissingMigrations ¶
func (m *Migrator) MissingMigrations(ctx context.Context) (MigrationSlice, error)
MissingMigrations returns applied migrations that can no longer be found.
func (*Migrator) Rollback ¶
func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*MigrationGroup, error)
type MigratorOption ¶
type MigratorOption func(m *Migrator)
func WithLocksTableName ¶
func WithLocksTableName(table string) MigratorOption
func WithMarkAppliedOnSuccess ¶
func WithMarkAppliedOnSuccess(enabled bool) MigratorOption
WithMarkAppliedOnSuccess sets the migrator to only mark migrations as applied/unapplied when their up/down is successful
func WithTableName ¶
func WithTableName(table string) MigratorOption