database

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMigrationFailed = errors.New("migration failed")

Functions

func NewDB added in v0.11.0

func NewDB(ctx context.Context, cfg *config.Database) (*sql.DB, error)

Types

type Migrator

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

Migrator runs goose migrations against the application database.

Runtime operations (Up, Down, Status, Redo) use the embedded migration files compiled into the binary. Create writes new files to disk and is intended for development only.

func NewMigrator

func NewMigrator(db *sql.DB, logger *slog.Logger) (*Migrator, error)

func (*Migrator) Create added in v0.10.0

func (m *Migrator) Create(name string) (string, error)

Create writes a new empty SQL migration file to disk. Development-only operation.

func (*Migrator) Down added in v0.10.0

func (m *Migrator) Down(ctx context.Context, steps int) ([]*goose.MigrationResult, error)

Down rolls back applied migrations. Steps must be > 0, or use DownAll.

func (*Migrator) DownAll added in v0.10.0

func (m *Migrator) DownAll(ctx context.Context) ([]*goose.MigrationResult, error)

DownAll rolls back all applied migrations.

func (*Migrator) Fresh added in v0.10.0

func (m *Migrator) Fresh(ctx context.Context) ([]*goose.MigrationResult, error)

Fresh drops all tables and re-applies all migrations from scratch. Development-only operation — equivalent to Laravel's migrate:fresh.

func (*Migrator) Redo added in v0.10.0

Redo rolls back the last migration and re-applies only that one migration.

func (*Migrator) Status added in v0.10.0

func (m *Migrator) Status(ctx context.Context) ([]*goose.MigrationStatus, error)

Status returns the status of all known migrations.

func (*Migrator) Up added in v0.10.0

func (m *Migrator) Up(ctx context.Context, steps int) ([]*goose.MigrationResult, error)

Up applies pending migrations. If steps <= 0, applies all pending migrations. Otherwise applies exactly that many steps.

type Options added in v0.11.0

type Options struct {
	Path   string
	Params map[string]string
	Pragma map[string]string
}

func (Options) DSN added in v0.11.0

func (o Options) DSN() string

Jump to

Keyboard shortcuts

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