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

migrate

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package migrate is a small SQLite migration runner shared across hive's databases. It applies embedded, versioned up SQL migrations (NNNN_name.up.sql) tracked in a schema_migrations table, one transaction per migration.

It is deliberately storage-agnostic: callers pass an fs.FS rooted at their migration files (e.g. fs.Sub(embedFS, "migrations")), so each database owns its own migration set while sharing this runner. Any bootstrapping specific to a database (such as seeding from a legacy version table) is the caller's responsibility: load the migrations, EnsureTable, do the bootstrap, then Apply.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppliedVersions

func AppliedVersions(ctx context.Context, conn *sql.DB) (map[int]bool, error)

AppliedVersions returns the set of already-applied migration versions.

func Apply

func Apply(ctx context.Context, conn *sql.DB, migrations []Migration) error

Apply ensures the tracking table exists, then applies every migration not already recorded, in ascending version order, one transaction each.

func EnsureTable

func EnsureTable(ctx context.Context, conn *sql.DB) error

EnsureTable creates the schema_migrations tracking table if it does not exist.

func Up

func Up(ctx context.Context, conn *sql.DB, fsys fs.FS) error

Up loads the migrations from fsys and applies all pending ones in version order. It does not perform any legacy bootstrapping; callers needing that should Load + EnsureTable + bootstrap + Apply instead.

Types

type Migration

type Migration struct {
	Version int
	Name    string
	UpSQL   string
}

Migration is a single versioned migration with its up SQL.

func Load

func Load(fsys fs.FS) ([]Migration, error)

Load parses NNNN_name.up.sql files from the root of fsys into a version-sorted slice. It validates the naming format and rejects duplicate versions.

Jump to

Keyboard shortcuts

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