Documentation
¶
Overview ¶
Package migrate combines registered SQL sources and runs Goose explicitly. Application SQL belongs to shared and module migration directories.
Index ¶
- func NewProvider(ctx context.Context, db *bun.DB, history fs.FS) (*goose.Provider, error)
- func Run(ctx context.Context, cfg database.Config, history fs.FS, action string, ...) (err error)
- func RunDB(ctx context.Context, db *bun.DB, history fs.FS, action string, ...) (err error)
- type Publication
- type Registry
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewProvider ¶
NewProvider runs a flat SQL history using the caller-owned Bun DB's dialect. Pass Registry.FS's result for registered sources or os.DirFS for a local history. A session lock serializes migration commands. Use direct/session-pooled connections.
func Run ¶
func Run(ctx context.Context, cfg database.Config, history fs.FS, action string, timeout time.Duration) (err error)
Run opens a dedicated database migration session, executes an explicit Goose action, and closes the pool. It never starts application services.
func RunDB ¶
func RunDB(ctx context.Context, db *bun.DB, history fs.FS, action string, timeout time.Duration) (err error)
RunDB runs migrations through a caller-owned database pool. Goose holds the advisory lock and migration work on its dedicated session; the pool stays open. Refresh requires at least two available connections: one holds the lock while the other replays migrations. Prefer Run for a dedicated refresh pool.
Types ¶
type Publication ¶
Publication reports either a newly published file or an existing application copy.
func Publish ¶
func Publish(ctx context.Context, directory string, driver database.Driver, tables ...Table) (results []Publication, err error)
Publish writes timestamped Goose migrations directly into directory. It opens no database connections, never overwrites files, and skips previously published tables even after their SQL is edited. Preserve each file's platform comment. A directory lock excludes concurrent publishers. Completed files remain on a later error; rerunning safely publishes the remaining files.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry collects migration directories during application assembly. Its zero value is ready to use. Register sequentially, then call FS before starting work. Sources are borrowed and must remain unchanged while their history is in use.
func (*Registry) FS ¶
FS combines all registered directories into one flat Goose history. Only SQL files directly in each source are included. Versions must be unique across all sources; ordering is by timestamp, not module registration order. An empty history is valid for assembly but Goose cannot run it. An empty driver means PostgreSQL, matching database defaults. No SQL is executed here.