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 ¶
- Variables
- func Apply(ctx context.Context, db *sql.DB, files fs.FS, dir string) error
- func ApplyPrefixed(ctx context.Context, db *sql.DB, files fs.FS, dir string, prefix string) error
- func ApplyVersioned(ctx context.Context, db *sql.DB, files fs.FS, dir string, versionTable string) error
- func Statements(body string) []string
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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.