Documentation
¶
Overview ¶
Package migration registers Go migrations and runs them through Goose.
Index ¶
- Constants
- Variables
- func ParseVersion(name string) (int64, error)
- func Register(name string, up, down Func)
- type Entry
- type Func
- type Migrator
- func (m *Migrator) Fresh(ctx context.Context) ([]Result, error)
- func (m *Migrator) Pretend(ctx context.Context) (map[string][]string, []string, error)
- func (m *Migrator) Refresh(ctx context.Context) ([]Result, error)
- func (m *Migrator) Reset(ctx context.Context) ([]Result, error)
- func (m *Migrator) Rollback(ctx context.Context, steps int) ([]Result, error)
- func (m *Migrator) Status(ctx context.Context) ([]Status, error)
- func (m *Migrator) Up(ctx context.Context, steps int) ([]Result, error)
- type Options
- type Registry
- type Result
- type Status
Constants ¶
const DefaultTable = "migrations"
DefaultTable is the bookkeeping table (Laravel calls it "migrations").
Variables ¶
var Default = NewRegistry()
Default is the registry used by Register and by the CLI.
Functions ¶
func ParseVersion ¶
ParseVersion extracts the numeric version from a migration name.
Types ¶
type Entry ¶
type Entry struct {
Version int64 // numeric prefix, e.g. 20261030061400
Name string // full name, e.g. 20261030061400_create_users_table
Up Func
Down Func
}
Entry is one registered migration.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator runs the migrations of a Registry against a database. Goose does the bookkeeping (version table, ordering, transactions); dbkit supplies the Schema Builder.
func New ¶
New creates a Migrator. driver is postgres, mysql or sqlite (aliases such as pgx and sqlite3 are accepted).
func (*Migrator) Fresh ¶
Fresh drops every table (including the bookkeeping table) and migrates from scratch. It is destructive.
type Options ¶
type Options struct {
// Table is the bookkeeping table. Default: "migrations".
Table string
// Lock enables a database-level lock so two deploys cannot migrate at
// the same time (PostgreSQL only).
Lock bool
}
Options configure a Migrator.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds migrations in memory. Migration files add themselves to Default from init(); tests can create their own Registry.
func (*Registry) MustRegister ¶
MustRegister is Register on a specific registry.