migrate

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package migrate installs and removes the Foreman schema with embedded 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 down to the target version.

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 or Down would run.

func Up

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

Up applies every pending migration.

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