migrate

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package migrate provides thin, testable helpers over bun/migrate plus a ready cobra command for running migrations from an application binary.

Index

Constants

This section is empty.

Variables

View Source
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 Down

func Down(ctx context.Context, db *bun.DB, ms *Migrations) (string, error)

Down rolls back the last applied migration group.

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.

func Status

func Status(ctx context.Context, db *bun.DB, ms *Migrations) (string, error)

Status returns applied and pending migrations.

func Up

func Up(ctx context.Context, db *bun.DB, ms *Migrations) (string, error)

Up applies all pending migrations and returns a human-readable summary.

Types

type DBProvider

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

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.

Jump to

Keyboard shortcuts

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