sqlmigration

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedDBKind = errors.New("sqlmigration: unsupported database kind")

ErrUnsupportedDBKind indicates the configured database dialect has no migration script or schema lookup query for the supplied Plan.

Functions

func LoadScript

func LoadScript(scripts embed.FS, kind config.DBKind) (string, error)

LoadScript returns the DDL script for the given dialect from the supplied embedded FS. Exported so callers that need the SQL text (e.g. integration tests) can re-use the lookup convention.

func Run

func Run(ctx context.Context, db orm.DB, plan Plan) error

Run executes the supplied Plan. It is a no-op when every expected table is already present and Pre hooks have completed without error.

Types

type Plan

type Plan struct {
	// Label is a short, human-readable identifier ("storage",
	// "event outbox", ...). Used as the error prefix.
	Label string
	// Kind is the database dialect.
	Kind config.DBKind
	// Scripts is the embedded SQL bundle. Run looks up
	// "scripts/<kind>.sql" within this FS.
	Scripts embed.FS
	// ExpectedTables names every table the migration must end up with.
	// The migration is skipped when all of them already exist.
	ExpectedTables []string
	// Pre is an optional list of steps that run before the
	// needs-migration probe (e.g. dropping obsolete tables left over
	// from earlier schema revisions). Each hook should be idempotent.
	Pre []func(ctx context.Context, db orm.DB) error
}

Plan describes one module's migration. Label appears in error messages so logs identify which module is being migrated.

Jump to

Keyboard shortcuts

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