github.com/peterldowns/pgtestdb
v0.1.1
#2592 most downloaded on Go modules
peterldowns/pgtestdb
What this package is like to depend on
Last release 16 days ago
07 Aug 2026
Release timing varies
gaps range from 2 weeks to 1.2 years
Rarely documented
notes for 2 of 12 stable releases
Nothing withdrawn
no release was ever pulled
3 years old
32 releases · first in 2023
1 release in the last 12 months
see the full history below
Release timeline
32 releases · Jun 2023 to Aug 2026Releases
latest 32-
v0.1.2-0.20260807145559-d39d3dc2ee5507 Aug 2026 pre-releaseNothing published for this version
-
v0.1.2-0.20250525174749-77928108820c25 May 2025 pre-releaseNothing published for this version
-
v0.1.2-0.20241203174208-603cfe2521da03 Dec 2024 pre-releaseNothing published for this version
-
v0.1.2-0.20241120133553-6d2f7fad74f820 Nov 2024 pre-releaseNothing published for this version
-
v0.1.2-0.20241015230050-63680a5e158715 Oct 2024 pre-releaseNothing published for this version
-
v0.1.2-0.20241015205312-75bd3b7fb09715 Oct 2024 pre-releaseNothing published for this version
-
v0.1.115 Oct 2024Release notes
Open source →Bugfix: GooseMigrator.Migrate() "dialect must be empty when using a custom store implementation"
This bug was first detected immediatley after pushing v0.1.0; CI passed locally but failed on main with this error:
? github.com/peterldowns/pgtestdb/internal/withdb [no test files] ok github.com/peterldowns/pgtestdb 2.544s ok github.com/peterldowns/pgtestdb/internal/multierr 0.003s ok github.com/peterldowns/pgtestdb/internal/once 0.003s ok github.com/peterldowns/pgtestdb/internal/sessionlock 0.289s ok github.com/peterldowns/pgtestdb/migrators/atlasmigrator 0.566s ok github.com/peterldowns/pgtestdb/migrators/bunmigrator 0.306s ok github.com/peterldowns/pgtestdb/migrators/common 0.010s ok github.com/peterldowns/pgtestdb/migrators/dbmatemigrator 0.475s ok github.com/peterldowns/pgtestdb/migrators/golangmigrator 0.286s ? github.com/peterldowns/pgtestdb/migrators/pgmigrator/migrations [no test files] --- FAIL: TestGooseMigratorFromDisk (0.07s) goose_test.go:21: failed to migrator.Migrate template testdb_tpl_b975d4cf2b5b60296612fea0fe385858: dialect must be empty when using a custom store implementation --- FAIL: TestGooseMigratorFromFS (0.08s) goose_test.go:66: failed to migrator.Migrate template testdb_tpl_f65054fab233eabdfb95c95f7bf2e12a: dialect must be empty when using a custom store implementation FAIL FAIL github.com/peterldowns/pgtestdb/migrators/goosemigrator 0.084s ok github.com/peterldowns/pgtestdb/migrators/pgmigrator 0.317s ok github.com/peterldowns/pgtestdb/migrators/sqlmigrator 0.217s ok github.com/peterldowns/pgtestdb/migrators/ternmigrator 0.186s FAILI introduced the bug in the
Migrate()method, but did not detect it locally because the migrator'sHash()resolved to a database template that I had already created in my local postgres server. So basically:- Work on the code, run tests, everything works and a database template is created for me locally.
- Work on the code some more, introduce the breaking problem, don't notice because
when the tests run they re-use the existing database template and don't actually
call
Migrate() - Release and push the code, resulting in CI failures on main because the database
template doesn't exist so the tests have to run the broken
Migrate()method.
Next time, I can avoid this type of problem by either:
- Using Github branches + PRs to merge in changes; CI is required to pass there before merging.
- Remembering to drop and recreate the test database server when working on changes that
modify the
Migrate()method.
Sloppy; my apologies.
-
v0.1.015 Oct 2024Release notes
Open source →Breaking: require go1.21.0+, drop support for go1.18, go1.19, go1.20
jackc/pgx/v5@latest uses some modern golang features like the
slicespackage, therefore requiring consumers to use go1.21 or higher.Additionally, some of the migrators now require 1.21+ as well.
The official golang release policy is:
Each major Go release is supported until there are two newer major releases.
Since go1.23 and go1.22 have been released, go1.21 isn't really supported any more, but it seems like a reasonable target and is about a year old. Ratcheting up from go1.18+ to go1.21+ seems fine to me and will allow some small quality of life improvements and make contributing easier.
Breaking: remove
Prepare()andVerify()frompgtestdb.Migrator// Now: type Migrator interface { Hash() (string, error) Migrate(context.Context, *sql.DB, Config) error } // Before: type Migrator interface { Hash() (string, error) Prepare(context.Context, *sql.DB, Config) error Migrate(context.Context, *sql.DB, Config) error Verify(context.Context, *sql.DB, Config) error }The
Prepare()method was removed because it was rarely used and none of the migrators implemented it, leading to confusion about when/how to implement it.- https://github.com/peterldowns/pgtestdb/issues/19
- https://github.com/peterldowns/pgtestdb/pull/6
If you were implementing
Prepare()in your custom migrator, you can achieve the same effect by moving that logic to the beginning of yourMigrate()function:type MyCustomMigrator struct { // ... } func (m *MyCustomMigrator) Migrate(ctx context.Context, db *sql.DB, cfg Config) error { // Code that was previously run in the `Prepare()` method if err := m.DoPreparations(ctx, db, cfg); err != nil { return err } // Migration logic if err := m.ApplyMigrationsLikeBefore(ctx, db, cfg); err != nil { return err } // If desired, any post-migrations customization, like inserting fixture data if err := m.DoPostMigrationLogic(ctx, db, cfg); err != nil { return err } return nil }The
Verify()method was only implemented by thepgmigrator.Migrator, and almost never detected any problems.Verify()was included in the interface because way back in the day, when I was first working on this library, I was somehow able to corrupt the template database prepared by the migrators. When tests ran, they would create an instance from the existing template, but the template was missing all the tables. Or something like that. At this point, I believe those consistency issues have been addressed. I have not seen a verification error since the public release of pgtestdb. The method is somewhat confusing, and I believe it's safe to remove it.If you were relying on logic in the
Verifymethod, you can move that logic to yourNewDB(t *testing.T)helper function:func NewDB(t *testing.T) *sql.DB { t.Helper() conf := pgtestdb.Config{ DriverName: "pgx", User: "postgres", Password: "password", Host: "localhost", Port: "5433", Options: "sslmode=disable", } var migrator pgtestdb.Migrator = &MyCustomMigrator{/* ... */} instanceConf := pgtestdb.Custom(t, conf, migrator) db, err := instanceConf.Connect() if err != nil { t.Fatalf("failed to connect to instance: %s", err) } // Run the Verify logic that was previously in the `Verify()` method of `MyCustomMigrator` if err := DoVerify(context.Background(), db, instanceConf); err != nil { t.Fatalf("failed to verify instance: %s", err) } return db }Non-breaking: update goosemigrator to use a goose.Provider
Goose v3 added a new goose.Provider type to allow users to run migrations without referencing a single package-level global variable. This is mostly an implementation detail but could result in warnings from the golang race detector in certain cases.
Previously, the goosemigrator used a RW-lock to guard access to this shared global and prevent race-detector warnings. Now that the
goose.Provideris available, thegoosemigratorhas been updated to use that instead.The
goosemigrator.GooseMigratorinterface is unchanged, and should behave the same as previously, but is now implemented differently. If you notice any problems please report them and I'll do my best to fix them.Non-breaking: other tweaks
-
The docker-compose and github actions files now use postgres:15 for testing pgtestdb. Previously we used postgis:15 in order to test that the default role was not allowed to enable superuser extensions, but I was able to update the tests to use the
pg_stat_statementsextension instead ofpostgisand confirm the same behavior. This makes developing against pgtestdb slightly easier and shouldn't impact correctness. -
In VSCode, if you open up any of the golang stdlib code files, the
goplsextension runs its analyses on them. This is annoying because it fills the VSCode "problems" view with lint errors that we cannot fix, because they're in the standard library, not our project's code. The only error I noticed was due tounusedparams, which we already lint for in our code withgolangci-lint, so I updated the shared VSCode settings to turn off this gopls analysis. -
Running
just tidyupdates all thego.modfiles for the main library and the migrators, but these should all be backwards-compatible changes.
Release notes
Open source →Breaking: require go1.21.0+, drop support for go1.18, go1.19, go1.20
jackc/pgx/v5@latest uses some modern golang features like the
slicespackage, therefore requiring consumers to use go1.21 or higher.Additionally, some of the migrators now require 1.21+ as well.
The official golang release policy is:
Each major Go release is supported until there are two newer major releases.
Since go1.23 and go1.22 have been released, go1.21 isn't really supported any more, but it seems like a reasonable target and is about a year old. Ratcheting up from go1.18+ to go1.21+ seems fine to me and will allow some small quality of life improvements and make contributing easier.
Breaking: remove
Prepare()andVerify()frompgmigrator.Migrator// Now: type Migrator interface { Hash() (string, error) Migrate(context.Context, *sql.DB, Config) error } // Before: type Migrator interface { Hash() (string, error) Prepare(context.Context, *sql.DB, Config) error Migrate(context.Context, *sql.DB, Config) error Verify(context.Context, *sql.DB, Config) error }The
Prepare()method was removed because it was rarely used and none of the migrators implemented it, leading to confusion about when/how to implement it.- https://github.com/peterldowns/pgtestdb/issues/19
- https://github.com/peterldowns/pgtestdb/pull/6
If you were implementing
Prepare()in your custom migrator, you can achieve the same effect by moving that logic to the beginning of yourMigrate()function:type MyCustomMigrator struct { // ... } func (m *MyCustomMigrator) Migrate(ctx context.Context, db *sql.DB, cfg Config) error { // Code that was previously run in the `Prepare()` method if err := m.DoPreparations(ctx, db, cfg); err != nil { return err } // Migration logic if err := m.ApplyMigrationsLikeBefore(ctx, db, cfg); err != nil { return err } // If desired, any post-migrations customization, like inserting fixture data if err := m.DoPostMigrationLogic(ctx, db, cfg); err != nil { return err } return nil }The
Verify()method was only implemented by thepgmigrator.Migrator, and almost never detected any problems.Verify()was included in the interface because way back in the day, when I was first working on this library, I was somehow able to corrupt the template database prepared by the migrators. When tests ran, they would create an instance from the existing template, but the template was missing all the tables. Or something like that. At this point, I believe those consistency issues have been addressed. I have not seen a verification error since the public release of pgtestdb. The method is somewhat confusing, and I believe it's safe to remove it.If you were relying on logic in the
Verifymethod, you can move that logic to yourNewDB(t *testing.T)helper function:// NewDB is a helper that returns an open connection to a unique and isolated // test database, fully migrated and ready for you to query. func NewDB(t *testing.T) *sql.DB { t.Helper() conf := pgtestdb.Config{ DriverName: "pgx", User: "postgres", Password: "password", Host: "localhost", Port: "5433", Options: "sslmode=disable", } // You'll want to use a real migrator, this is just an example. See the rest // of the docs for more information. var migrator pgtestdb.Migrator = &MyCustomMigrator{/* ... */} instanceConf := pgtestdb.Custom(t, conf, migrator) db, err := instanceConf.Connect() if err != nil { t.Fatalf("failed to connect to instance: %s", err) } // Run the Verify logic that was previously in the `Verify()` method of `MyCustomMigrator` if err := DoVerify(context.Background(), db, instanceConf); err != nil { t.Fatalf("faield to verify instance: %s", err) } return db }Non-breaking: update goosemigrator to use a goose.Provider
Goose v3 added a new goose.Provider type to allow users to run migrations without referencing a single package-level global variable. This is mostly an implementation detail but could result in warnings from the golang race detector in certain cases.
Previously, the goosemigrator used a RW-lock to guard access to this shared global and prevent race-detector warnings. Now that the
goose.Provideris available, thegoosemigratorhas been updated to use that instead.The
goosemigrator.GooseMigratorinterface is unchanged, and should behave the same as previously, but is now implemented differently. If you notice any problems please report them and I'll do my best to fix them.Non-breaking: other tweaks
-
The docker-compose and github actions files now use postgres:15 for testing pgtestdb. Previously we used postgis:15 in order to test that the default role was not allowed to enable superuser extensions, but I was able to update the tests to use the
pg_stat_statementsextension instead ofpostgisand confirm the same behavior. This makes developing against pgtestdb slightly easier and shouldn't impact correctness. -
In VSCode, if you open up any of the golang stdlib code files, the
goplsextension runs its analyses on them. This is annoying because it fills the VSCode "problems" view with lint errors that we cannot fix, because they're in the standard library, not our project's code. The only error I noticed was due tounusedparams, which we already lint for in our code withgolangci-lint, so I updated the shared VSCode settings to turn off this gopls analysis. -
Running
just tidyupdates all thego.modfiles for the main library and the migrators, but these should all be backwards-compatible changes.
-
v0.0.16-0.20241015202427-a69306f4a2b515 Oct 2024 pre-releaseNothing published for this version
-
v0.0.16-0.20240925221734-1e5d91b9e89d25 Sep 2024 pre-releaseNothing published for this version
-
v0.0.16-0.20240925220510-25043e5caa6025 Sep 2024 pre-releaseNothing published for this version
-
v0.0.1525 Sep 2024Nothing published for this version
-
v0.0.15-0.20240715203743-5b0be700a39615 Jul 2024 pre-releaseNothing published for this version
-
v0.0.15-0.20240526160428-4a2e20820f4e26 May 2024 pre-releaseNothing published for this version
-
v0.0.1404 Apr 2024Nothing published for this version
-
v0.0.14-0.20240404165528-d942f838c90b04 Apr 2024 pre-releaseNothing published for this version
-
v0.0.1304 Apr 2024Nothing published for this version
-
v0.0.1210 Dec 2023Nothing published for this version
-
v0.0.12-0.20231210025420-80800140529f10 Dec 2023 pre-releaseNothing published for this version
-
v0.0.12-0.20230706210835-527f0b52be5306 Jul 2023 pre-releaseNothing published for this version
-
v0.0.1105 Jul 2023Nothing published for this version
-
v0.0.11-0.20230606182415-fb6e94d5fc5106 Jun 2023 pre-releaseNothing published for this version
-
v0.0.1006 Jun 2023Nothing published for this version
-
v0.0.902 Jun 2023Nothing published for this version
-
v0.0.801 Jun 2023Nothing published for this version
-
v0.0.601 Jun 2023Nothing published for this version
-
v0.0.501 Jun 2023Nothing published for this version
-
v0.0.0-20240715203743-5b0be700a39615 Jul 2024 pre-releaseNothing published for this version
-
v0.0.0-20240526160428-4a2e20820f4e26 May 2024 pre-releaseNothing published for this version
-
v0.0.0-20240404165528-d942f838c90b04 Apr 2024 pre-releaseNothing published for this version
-
v0.0.0-20231210025420-80800140529f10 Dec 2023 pre-releaseNothing published for this version
-
v0.0.0-20230601203800-fa9611cdf36401 Jun 2023 pre-releaseNothing published for this version