sqlmigrate

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sqlmigrate applies a service's embedded migration files to a database/sql handle, so a service's store directory holds its .sql files and nothing else: the files are the only schema source, and this is the one runner that reads them.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidVersionTable = errors.New("sqlmigrate: a version table name must be a lower-case identifier")

ErrInvalidVersionTable means a version table name is not a plain identifier.

Functions

func Apply

func Apply(ctx context.Context, db *sql.DB, files fs.FS, dir string) error

Apply brings db up to every *.up.sql file under dir in files, in name order, skipping the ones schema_migrations already records. Each file is executed one statement at a time so a driver that runs one statement per call (candace/pkg/pgmem in tests) applies the same bytes production does.

func ApplyPrefixed

func ApplyPrefixed(ctx context.Context, db *sql.DB, files fs.FS, dir string, prefix string) error

ApplyPrefixed applies a component schema while namespacing its migration receipts in a database shared with an owning application. Prefix is only a ledger namespace; it never changes the embedded filename or execution order.

func ApplyVersioned added in v0.2.0

func ApplyVersioned(ctx context.Context, db *sql.DB, files fs.FS, dir string, versionTable string) error

ApplyVersioned applies every *.sql file under dir (except *.down.sql), in name order, recording each in versionTable. A migration set with its own version table is numbered independently: a component such as CSF and the application that embeds it each keep their own table in one database, and neither run sees the other's files.

func Statements

func Statements(body string) []string

Statements splits one migration file into the statements it holds. The files hold plain DDL with no semicolons inside literals. Full-line -- comments are removed before semicolons are interpreted as delimiters.

Types

This section is empty.

Jump to

Keyboard shortcuts

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