dbmig

package
v0.10.257 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package dbmig applies forward-only SQLite schema migrations.

Apply works with database/sql so callers own SQLite connection setup. The cr ledger startup path should still enforce its own connection contract, including single-writer behavior or db.SetMaxOpenConns(1).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPlan means the compiled migration list is internally
	// inconsistent and should be fixed in code before opening user data.
	ErrInvalidPlan = errors.New("dbmig: invalid migration plan")
	// ErrInvalidMeta means durable schema metadata is malformed; callers should
	// fail loudly rather than trying to repair it implicitly.
	ErrInvalidMeta = errors.New("dbmig: invalid meta state")
	// ErrDowngrade means the database schema is newer than this binary knows how
	// to operate.
	ErrDowngrade = errors.New("dbmig: database schema newer than code")
)

Functions

This section is empty.

Types

type AppliedMigration

type AppliedMigration struct {
	Version int
	Name    string
}

AppliedMigration records a migration that ran during Apply.

type Migration

type Migration struct {
	Version int
	Name    string
	Up      func(context.Context, *sql.Tx) error
}

Migration is one forward-only schema migration.

type Result

type Result struct {
	PreviousVersion int
	CurrentVersion  int
	Applied         []AppliedMigration
}

Result summarizes one Apply invocation.

func Apply

func Apply(ctx context.Context, db *sql.DB, migrations []Migration) (Result, error)

Apply ensures meta exists, refuses downgrades, and applies missing migrations in version order.

Jump to

Keyboard shortcuts

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