Documentation
¶
Overview ¶
Package sqlmigration provides the framework-internal DDL migration helper shared by every module that ships its own SQL scripts (approval, storage, event inbox, event outbox).
Each caller supplies an embedded script bundle plus the list of tables that must exist after the migration. Run inspects the schema dictionary for the configured dialect, skips when every expected table is already present, and otherwise executes the per-dialect script as a single batch. Optional Pre hooks let callers attach drop-obsolete-tables steps before the create script runs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.
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.