migrate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package migrate installs and removes the Foreman schema with embedded, transactional SQL migrations.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownVersion = errors.New("migrate: database has a version this binary does not know")

ErrUnknownVersion reports a database migrated by a newer Foreman.

Functions

func Down

func Down(ctx context.Context, db DB, opts ...Option) error

Down reverts migrations newest first down to the target version (0 by default, which removes every Foreman object but keeps the schema).

func Latest

func Latest() int

Latest returns the newest version embedded in this binary.

func SQL

func SQL(up bool, opts ...Option) (string, error)

SQL returns the statements Up (up=true) or Down would run on an empty (or fully migrated) database, for users who apply migrations with their own tools. The migrations table is included.

func Up

func Up(ctx context.Context, db DB, opts ...Option) error

Up applies every pending migration, each in its own transaction. Runs are serialised across processes by an advisory lock, so concurrent clients starting at once are safe; Up on an up-to-date schema is a no-op.

func Version

func Version(ctx context.Context, db DB, opts ...Option) (int, error)

Version returns the current schema version (0 when not installed).

Types

type DB

type DB interface {
	Begin(ctx context.Context) (pgx.Tx, error)
}

DB is satisfied by *pgxpool.Pool and *pgx.Conn.

type Migration

type Migration struct {
	Version int
	Name    string
	// contains filtered or unexported fields
}

Migration is one embedded schema version.

func Migrations

func Migrations() ([]Migration, error)

Migrations returns the embedded migrations in version order.

type Option

type Option func(*options)

Option configures a migration run.

func WithSchema

func WithSchema(schema string) Option

WithSchema installs Foreman into schema instead of public.

func WithTargetVersion

func WithTargetVersion(v int) Option

WithTargetVersion stops Down at version v instead of removing everything.

Jump to

Keyboard shortcuts

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