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

# README

pgmigrator

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

pgmigrator provides a migrator that can be used out of the box with projects that use peterldowns/pgmigrate for migrations.

You can use migrations from disk or from an embedded FS, and you can set the table name that the migration records are stored in. Here's an example:

func TestPGMigratorFromDisk(t *testing.T) {
	dir := os.DirFS("migrations")
	pgm, err := pgmigrator.New(dir)
	assert.Nil(t, err)
	db := pgtestdb.New(t, pgtestdb.Config{
		DriverName: "pgx",
		Host:       "localhost",
		User:       "postgres",
		Password:   "password",
		Port:       "5433",
		Options:    "sslmode=disable",
	}, pgm)
	assert.NotEqual(t, nil, db)
}

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

func TestPGMigratorFromFSAndWithOptions(t *testing.T) {
	logger := pgmigrate.NewTestLogger(t)
	pgm, err := pgmigrator.New(
		exampleFS,
		pgmigrator.WithTableName("example_table_name"),
		pgmigrator.WithLogger(logger),
	)
	assert.Nil(t, err)
	db := pgtestdb.New(t, pgtestdb.Config{
		DriverName: "pgx",
		Host:       "localhost",
		User:       "postgres",
		Password:   "password",
		Port:       "5433",
		Options:    "sslmode=disable",
	}, pgm)
	assert.NotEqual(t, nil, db)
}

# Packages

No description provided by the author

# Functions

New returns a [PGMigrator], which is a pgtestdb.Migrator that uses pgmigrate to perform migrations.
WithLogger sets the [pgmigrate.Logger] to use when applying migrations.
WithTableName specifies the name of the table in which pgmigrate will store its migration records.

# Structs

PGMigrator is a pgtestdb.Migrator that uses pgmigrate to perform migrations.

# Type aliases

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