Documentation
¶
Overview ¶
Package migrate provides thin, testable helpers over bun/migrate plus a ready cobra command for running migrations from an application binary.
Index ¶
- Variables
- func Create(ms *Migrations, name string) (string, error)
- func Down(ctx context.Context, db *bun.DB, ms *Migrations) (string, error)
- func NewCommand(dbFn DBProvider, ms *Migrations) *cobra.Command
- func Status(ctx context.Context, db *bun.DB, ms *Migrations) (string, error)
- func Up(ctx context.Context, db *bun.DB, ms *Migrations) (string, error)
- type DBProvider
- type Migrations
- type MigrationsOption
Constants ¶
This section is empty.
Variables ¶
var WithMigrationsDirectory = bunmigrate.WithMigrationsDirectory
WithMigrationsDirectory pins the directory used by Create (so it does not rely on runtime.Caller).
Functions ¶
func Create ¶
func Create(ms *Migrations, name string) (string, error)
Create scaffolds a new empty Go migration file in the migrations directory (which must already exist). The generated file uses package "migrations"; keep the migrations directory named "migrations" (the generated layout uses internal/migrations). It does not need a database connection.
func NewCommand ¶
func NewCommand(dbFn DBProvider, ms *Migrations) *cobra.Command
NewCommand builds the "migrate" cobra command with up/down/status/create children, wired to the core funcs. Mount it on the app root command.
Types ¶
type DBProvider ¶
DBProvider lazily opens the application database. Only up/down/status call it.
type Migrations ¶
type Migrations = bunmigrate.Migrations
Migrations is the bun migration collection. Re-exported so projects can declare migrations without importing bun/migrate directly.
func NewMigrations ¶
func NewMigrations(opts ...MigrationsOption) *Migrations
NewMigrations creates a migration collection.
type MigrationsOption ¶
type MigrationsOption = bunmigrate.MigrationsOption
MigrationsOption configures a Migrations collection.