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 ¶
Types ¶
type Migration ¶
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.