migrate

package
v1.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2022 License: BSD-2-Clause Imports: 15 Imported by: 164

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoMigrationOption added in v0.3.4

type GoMigrationOption func(cfg *goMigrationConfig)

func WithPackageName added in v0.3.4

func WithPackageName(name string) GoMigrationOption

type Migration

type Migration struct {
	bun.BaseModel

	ID         int64 `bun:",pk,autoincrement"`
	Name       string
	GroupID    int64
	MigratedAt time.Time `bun:",notnull,nullzero,default:current_timestamp"`

	Up   MigrationFunc `bun:"-"`
	Down MigrationFunc `bun:"-"`
}

func (*Migration) IsApplied added in v0.3.1

func (m *Migration) IsApplied() bool

func (*Migration) String added in v0.3.0

func (m *Migration) String() string

type MigrationFile added in v0.3.0

type MigrationFile struct {
	Name    string
	Path    string
	Content string
}

type MigrationFunc

type MigrationFunc func(ctx context.Context, db *bun.DB) error

func NewSQLMigrationFunc

func NewSQLMigrationFunc(fsys fs.FS, name string) MigrationFunc

type MigrationGroup added in v0.3.0

type MigrationGroup struct {
	ID         int64
	Migrations MigrationSlice
}

func (*MigrationGroup) IsZero added in v0.3.1

func (g *MigrationGroup) IsZero() bool

func (*MigrationGroup) String added in v0.3.0

func (g *MigrationGroup) String() string

type MigrationOption added in v0.3.1

type MigrationOption func(cfg *migrationConfig)

func WithNopMigration added in v0.3.1

func WithNopMigration() MigrationOption

type MigrationSlice added in v0.3.0

type MigrationSlice []Migration

func (MigrationSlice) Applied added in v0.3.1

func (ms MigrationSlice) Applied() MigrationSlice

Applied returns applied migrations in descending order (the order is important and is used in Rollback).

func (MigrationSlice) LastGroup added in v0.3.1

func (ms MigrationSlice) LastGroup() *MigrationGroup

LastGroup returns the last applied migration group.

func (MigrationSlice) LastGroupID added in v0.3.1

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 added in v0.3.0

func (ms MigrationSlice) String() string

func (MigrationSlice) Unapplied added in v0.3.1

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 added in v0.4.1

func (m *Migrations) Add(migration Migration)

func (*Migrations) Discover

func (m *Migrations) Discover(fsys fs.FS) error

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 added in v0.3.1

func (m *Migrations) Sorted() MigrationSlice

type MigrationsOption

type MigrationsOption func(m *Migrations)

func WithMigrationsDirectory added in v0.3.0

func WithMigrationsDirectory(directory string) MigrationsOption

type Migrator added in v0.3.0

type Migrator struct {
	// contains filtered or unexported fields
}

func NewMigrator added in v0.3.0

func NewMigrator(db *bun.DB, migrations *Migrations, opts ...MigratorOption) *Migrator

func (*Migrator) CreateGoMigration added in v0.3.4

func (m *Migrator) CreateGoMigration(
	ctx context.Context, name string, opts ...GoMigrationOption,
) (*MigrationFile, error)

CreateGoMigration creates a Go migration file.

func (*Migrator) CreateSQLMigrations added in v0.3.4

func (m *Migrator) CreateSQLMigrations(ctx context.Context, name string) ([]*MigrationFile, error)

CreateSQLMigrations creates an up and down SQL migration files.

func (*Migrator) DB added in v0.3.1

func (m *Migrator) DB() *bun.DB

func (*Migrator) Init added in v0.3.0

func (m *Migrator) Init(ctx context.Context) error

func (*Migrator) Lock added in v0.3.0

func (m *Migrator) Lock(ctx context.Context) error

func (*Migrator) MarkApplied added in v0.3.1

func (m *Migrator) MarkApplied(ctx context.Context, migration *Migration) error

MarkApplied marks the migration as applied (completed).

func (*Migrator) MarkUnapplied added in v0.3.1

func (m *Migrator) MarkUnapplied(ctx context.Context, migration *Migration) error

MarkUnapplied marks the migration as unapplied (new).

func (*Migrator) Migrate added in v0.3.0

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 added in v0.3.1

func (m *Migrator) MigrationsWithStatus(ctx context.Context) (MigrationSlice, error)

MigrationsWithStatus returns migrations with status in ascending order.

func (*Migrator) Reset added in v0.4.1

func (m *Migrator) Reset(ctx context.Context) error

func (*Migrator) Rollback added in v0.3.0

func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*MigrationGroup, error)

func (*Migrator) Unlock added in v0.3.0

func (m *Migrator) Unlock(ctx context.Context) error

type MigratorOption added in v0.3.0

type MigratorOption func(m *Migrator)

func WithLocksTableName

func WithLocksTableName(table string) MigratorOption

func WithTableName

func WithTableName(table string) MigratorOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL