Help us shape the future of Go! Take the 2026 Go Developer Survey

dbmigrate

package
v1.7.7 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dbmigrate runs ordered, one-way schema steps against the SQLite database. A one-row schema_version table records how many steps have been applied; each pending step runs in its own transaction, so a failure leaves the database at the last step that completed. Before the first pending step on a database that holds data, the database is copied aside.

Index

Constants

This section is empty.

Variables

View Source
var ErrDanglingForeignKey = errors.New("foreign key check failed: a row points at nothing")

ErrDanglingForeignKey is returned when a step leaves a row pointing at nothing.

View Source
var ErrNewerDatabase = errors.New("database is newer than this release")

ErrNewerDatabase is returned when the database was migrated by a newer release.

Functions

This section is empty.

Types

type Result

type Result struct {
	// Applied is how many steps ran this start.
	Applied int
	// BackupPath is the copy taken before the first step, empty when none was needed.
	BackupPath string
}

Result says what Run did.

func Run

func Run(ctx context.Context, db *sql.DB, dbPath string, steps []Step, log *slog.Logger) (Result, error)

Run brings the database up to len(steps). A database with no tables at all is fresh: it is stamped as current without running anything, because the stores create their tables in the newest shape. A database stamped with more steps than this binary knows is refused, since an older binary must not guess at a newer schema.

type Step

type Step struct {
	Name string
	Run  func(ctx context.Context, tx *sql.Tx) error
}

Step is one schema change. Run gets the transaction the step commits in and must not commit or roll it back itself.

Jump to

Keyboard shortcuts

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