migrate

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package migrate applies embedded SQL migrations. It is shared by the postgres and sqlite stores, which each embed their own migration files.

Migration files are named NNNN_description.sql and applied in version order, each in its own transaction. Applied versions are recorded in the schema_migrations table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

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

Apply runs all migrations that have not been applied yet.

func Pending

func Pending(ctx context.Context, db *sql.DB, migrations []Migration) (bool, error)

Pending reports whether any migration has not been applied. It returns an error if the database is unreachable or has never been migrated.

Types

type LockFunc

type LockFunc func(ctx context.Context, conn *sql.Conn) (unlock func(), err error)

LockFunc acquires an exclusive, cross-process migration lock on conn and returns a function that releases it.

type Migration

type Migration struct {
	Version int
	Name    string
	SQL     string
}

func Load

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

Load reads migrations from the root of fsys.

Jump to

Keyboard shortcuts

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