dbmigrate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dbmigrate runs an embedded goose migration chain against a PostgreSQL database. Every service ships its own chain and its own connection string; what they share is the machinery around goose — the single-connection pool the session lock needs, the advisory lock that serializes concurrent runs, and the error wrapping an operator reads. That machinery lives here so a fix to it reaches every service.

The chain is a plain fs.FS, which is what the embedding package exposes, so a service's store package is a name for its chain and the table that chain books its applied versions in, and nothing more.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownTo

func DownTo(ctx context.Context, dbURL string, chain fs.FS, versionTable string, version int64) ([]int64, error)

DownTo rolls chain back to version, applying the down migration of everything above it, and returns the versions it rolled back. Passing 0 leaves an empty schema.

It is the counterpart of Up: a chain ships down migrations, and a rollback nobody can run is a rollback that does not exist.

func Up

func Up(ctx context.Context, dbURL string, chain fs.FS, versionTable string) ([]int64, error)

Up applies every pending migration of chain and returns the versions it applied, oldest first. An up-to-date database yields an empty slice and no error.

Types

type MigrationState

type MigrationState struct {
	// Version is the migration's version, the number its file name starts with.
	Version int64
	// Applied says whether the database has this migration.
	Applied bool
}

MigrationState is one migration of a chain and whether the database carries it. It is what answers "which schema is this database on" before code that assumes a newer one is run against it.

func Status

func Status(ctx context.Context, dbURL string, chain fs.FS, versionTable string) ([]MigrationState, error)

Status reports every migration of chain against the database, oldest first.

Jump to

Keyboard shortcuts

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