hoppermigrate

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 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.

The embedded scripts are Postgres's. A driver for another engine supplies its own script for each version (driver.MigrationScripts), and Up and Down apply those, at the same versions; such a driver also returns its scripts for other tools, as hoppersqlite.Migrations does. A new schema version therefore needs a script for each engine.

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, with Postgres's scripts. A driver for another engine has its own (hoppersqlite.Migrations, for SQLite).

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