database

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 17 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.

Methods that apply migrations return []*goose.MigrationResult and error. On partial failure goose returns a *goose.PartialError containing both the successfully applied migrations and the failed one. Migrator preserves this contract — callers can use errors.As to extract partial results when needed.

func NewMigrator

func NewMigrator(db *sql.DB, cfg *config.Database) (*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

Fresh deletes the SQLite database file and re-applies all migrations from scratch. Development-only operation — equivalent to Laravel's migrate:fresh.

This avoids FK constraint issues during rollback by removing the file entirely. The database connection is closed, the file is deleted, a new connection is opened via NewDB, and the goose provider is recreated before running Up.

After Fresh returns, the old *sql.DB (held by other components via Wire) is closed. This is safe because Fresh is a CLI-only operation — the process exits after it.

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.

On partial failure the error wraps *goose.PartialError with applied results.

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