migrations

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package migrations versions the database schema.

Each Migration runs once per database, in ID order, and is recorded in the schema_migrations table. A database lock (PostgreSQL advisory lock, MySQL GET_LOCK) serializes runners, so API replicas, init containers and `gohead migrate` can start at the same time safely.

Adding a migration: append to All with the next ID. Write it so it also works on a fresh database where 0001_baseline already created the latest models (check with tx.Migrator().HasColumn/HasTable before changing), and give it a Down when it can be undone. Never edit a released migration.

Index

Constants

This section is empty.

Variables

View Source
var All = []Migration{
	{
		ID:          "0001_baseline",
		Description: "Tables of GoHead 0.5 (creates them, or brings databases from earlier versions up to date)",
		Up:          baseline,
	},
	{
		ID:          "0002_revisions",
		Description: "Content revisions (history of every entry change)",
		Up:          func(tx *gorm.DB) error { return tx.AutoMigrate(&revision0002{}) },
		Down:        func(tx *gorm.DB) error { return tx.Migrator().DropTable(&revision0002{}) },
	},
	{
		ID:          "0003_i18n",
		Description: "Locales, localized attributes and translations",
		Up:          i18nUp,
		Down:        i18nDown,
	},
	{
		ID:          "0004_agent_reviews",
		Description: "Agent proposals awaiting approval, approval setting, test runs",
		Up:          agentsV2Up,
		Down:        agentsV2Down,
	},
	{
		ID:          "0005_public_role",
		Description: "Rename a custom role named public, now the role of anonymous visitors",
		Up:          publicRoleUp,
		Down:        publicRoleDown,
	},
	{
		ID:          "0006_jobs",
		Description: "Jobs table of the database job queue (GoHead without Redis)",
		Up:          jobsUp,
		Down:        jobsDown,
	},
	{
		ID:          "0007_connections",
		Description: "Connected apps: remote MCP servers whose tools agents can use",
		Up:          connectionsUp,
		Down:        connectionsDown,
	},
	{
		ID:          "0008_user_sso",
		Description: "Accounts linked to an identity provider (sign-in with Google)",
		Up:          userSSOUp,
		Down:        userSSODown,
	},
}

All lists the migrations in order.

View Source
var ErrPending = errors.New("database schema is not up to date")

ErrPending is returned by Check when migrations have not run.

Functions

func Check added in v0.5.0

func Check(db *gorm.DB) error

Check returns ErrPending (with the pending IDs) when migrations have not run, for processes that must not change the schema themselves.

func Down added in v0.5.0

func Down(db *gorm.DB, steps int) ([]string, error)

Down reverts the last `steps` applied migrations, newest first.

func MigrateDatabase

func MigrateDatabase(db *gorm.DB) error

MigrateDatabase applies every pending migration. Kept for callers (and tests) that only need an up-to-date schema.

func Up added in v0.5.0

func Up(db *gorm.DB) ([]string, error)

Up applies the pending migrations and returns their IDs.

Types

type Migration added in v0.5.0

type Migration struct {
	ID          string // sortable, e.g. "0002_item_locale"
	Description string
	Up          func(tx *gorm.DB) error
	Down        func(tx *gorm.DB) error // nil: cannot be undone
}

Migration is one versioned schema change.

type State added in v0.5.0

type State struct {
	ID          string
	Description string
	AppliedAt   *time.Time // nil: pending
	Reversible  bool
}

State is a migration and whether it ran.

func Status added in v0.5.0

func Status(db *gorm.DB) ([]State, error)

Status lists every migration with when it was applied.

Jump to

Keyboard shortcuts

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