Skip to content

Latest commit

 

History

History

goosemigrator

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

goosemigrator

go get github.com/peterldowns/pgtestdb/migrators/goosemigrator@latest

goosemigrator provides migrators that can be used out of the box with projects that use pressly/goose for migrations.

Currently only SQL migrations are supported, and can be read from a directory on disk or from an embedded filesystem. Golang-defined migrations are not supported by default.

You can configure the migrations directory, the table name, and the filesystem being used. Here's an example:

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)
}

//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)
}