Categorygithub.com/peterldowns/pgtestdb/migrators/golangmigrator
modulepackage
0.1.1
Repository: https://github.com/peterldowns/pgtestdb.git
Documentation: pkg.go.dev

# README

golangmigrator

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

golangmigrator provides a migrator that can be used out of the box with projects that use golang-migrate/migrate for migrations.

Because Hash() requires calculating a unique hash based on the contents of the migrations, this implementation only supports reading migration files from disk or an embedded filesystem.

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

//go:embed migrations/*.sql
var exampleFS embed.FS

func TestMigrateFromEmbeddedFS(t *testing.T) {
  gm := golangmigrator.New(
    "migrations",
    golangmigrator.WithFS(exampleFS),
  )

  db := pgtestdb.New(t, pgtestdb.Config{
    Host:     "localhost",
    User:     "postgres",
    Password: "password",
    Port:     "5433",
    Options:  "sslmode=disable",
  }, gm)
  assert.NotEqual(t, nil, db)
}

func TestMigrateFromDisk(t *testing.T) {
  gm := golangmigrator.New("migrations")
  db := pgtestdb.New(t, pgtestdb.Config{
    Host:     "localhost",
    User:     "postgres",
    Password: "password",
    Port:     "5433",
    Options:  "sslmode=disable",
  }, gm)
  assert.NotEqual(t, nil, db)
}

# Functions

New returns a [GolangMigrator], which is a pgtestdb.Migrator that uses golang-migrate to perform migrations.
WithFS specifies a `fs.FS` from which to read the migration files.

# Structs

GolangMigrator is a pgtestdb.Migrator that uses golang-migrate to perform migrations.

# Type aliases

Option provides a way to configure the GolangMigrator struct and its behavior.