You can initialize a migrator using goosemigrator.New(). You can configure the migrations directory, the migration table name, and the filesystem used via functional options.
Migrations from a disk directory
Pass the directory name as the first argument to goosemigrator.New().
func TestGooseMigratorFromDisk(t *testing.T) {
m := goosemigrator.New("migrations")
db := pgtestdb.New(t, pgtestdb.Config{
DriverName: "pgx",
Host: "localhost",
User: "postgres",
Password: "password",
Port: "5433",
Options: "sslmode=disable",
}, m)
assert.NotEqual(t, nil, db)
}
Migrations from an embedded filesystem
Use goosemigrator.WithFS(fs) to provide an embed.FS and goosemigrator.WithTableName(name) to specify a custom migration table name.
//go:embed migrations/*.sql
var exampleFS embed.FS
func TestGooseMigratorFromFS(t *testing.T) {
gm := goosemigrator.New(
"migrations",
goosemigrator.WithFS(exampleFS),
goosemigrator.WithTableName("goose_example_migrations"),
)
db := pgtestdb.New(t, pgtestdb.Config{
DriverName: "pgx",
Host: "localhost",
User: "postgres",
Password: "password",
Port: "5433",
Options: "sslmode=disable",
}, gm)
assert.NotEqual(t, nil, db)
}