migrations

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package migrations handles database schema migrations with version tracking.

Migration System:

  • Each migration has a unique version number
  • schema_version table tracks applied migrations
  • Migrations run in transaction (all-or-nothing)
  • Bootstrap migration detects pre-existing databases

Adding New Migration:

  1. Create file XXX_descriptive_name.go (XXX = next version number)
  2. Register migration in init() using migrations.Register()
  3. Implement up(tx) function with schema changes
  4. Add verification test in runner_test.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(m Migration)

Register registers a migration. Called from init() functions.

Types

type Migration

type Migration struct {
	Version     int
	Description string
	Up          func(tx *sql.Tx) error
}

Migration represents a single schema migration.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner executes migrations in order.

func NewRunner

func NewRunner(db *sql.DB, logger *slog.Logger) *Runner

NewRunner creates a new migration runner.

func (*Runner) Run

func (r *Runner) Run() error

Run executes all pending migrations.

Jump to

Keyboard shortcuts

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