hoppermigrate

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package hoppermigrate installs and upgrades hopper's database schema.

Migrations are SQL files embedded in this package, versioned and applied in order. They run under a cross-process lock taken on a dedicated connection, so any number of replicas can call Up at startup. The raw files are also available through Migrations for teams that run migrations with their own tool; hopper_schema records the applied versions either way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Latest

func Latest() int

Latest returns the newest schema version this package knows.

func Version

func Version[TTx any](ctx context.Context, d driver.Driver[TTx]) (int, error)

Version returns the installed schema version, or 0 if hopper's schema has not been installed.

Types

type Migration

type Migration struct {
	Version int
	Name    string
	Up      string
	Down    string
}

Migration is one schema version with its up and down scripts.

func Migrations

func Migrations() []Migration

Migrations returns every known migration in ascending version order.

type Options

type Options struct {
	// Target is the version to stop at. For Up it defaults to the latest
	// version; for Down it defaults to 0, which removes the schema entirely.
	Target int
	// Logger defaults to slog.Default().
	Logger *slog.Logger
}

Options tunes a migration run. A nil *Options means the defaults.

type Result

type Result struct {
	// Applied lists the versions applied (Up) or reverted (Down), in order.
	Applied []int
	// Version is the schema version afterwards, or 0 if none is installed.
	Version int
}

Result reports what a migration run did.

func Down

func Down[TTx any](ctx context.Context, d driver.Driver[TTx], opts *Options) (*Result, error)

Down reverts migrations from the current version down to Target. It exists for development; production schemas move forward only.

func Up

func Up[TTx any](ctx context.Context, d driver.Driver[TTx], opts *Options) (*Result, error)

Up applies every migration above the current version, up to Target. It is safe to call from several processes at once and is a no-op when the schema is current.

Jump to

Keyboard shortcuts

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