Documentation
¶
Overview ¶
Package migrate runs versioned SQL migrations against a gormx-managed database using goose. It is an opt-in module so the core framework stays free of a migration-tool dependency: import it only where you need migrations.
Typical use is from a host Setup handler, which runs after the database is connected but before the server starts serving:
//go:embed migrations/*.sql
var migrationsFS embed.FS
app.WithModule(gormx.Module(postgres.Driver())).
Setup(func(a *host.App) error {
return migrate.Up(context.Background(), gormx.Of(a), migrationsFS)
})
Index ¶
Constants ¶
const DefaultDir = "migrations"
DefaultDir is the directory within the provided fs.FS that holds migration files. It matches the common `//go:embed migrations/*.sql` layout.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator applies and inspects migrations for a single database. Build one with New and reuse it; it is safe for sequential use.
func New ¶
New builds a Migrator for db, reading migration files from fsys. The goose dialect is derived from the gorm driver, so the same call works for Postgres, SQLite, and MySQL.
type Option ¶
type Option func(*config)
Option configures a Migrator.
func WithDir ¶
WithDir overrides the directory within the fs.FS that holds migration files (default "migrations"). Pass "." when the fs.FS is already rooted at the migrations directory.
func WithLogger ¶
WithLogger sets the logger used to report applied/rolled-back migrations.