Skip to content

Commit

Permalink
bugfix(goosemigrator): fix "dialect must be empty" error in Migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
peterldowns committed Oct 15, 2024
1 parent 88528d2 commit 29c5e55
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 13 deletions.
54 changes: 53 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,58 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
-->

## [v0.1.1] - 2024-10-15

### 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](https://github.com/peterldowns/pgtestdb/actions/runs/11353832019/job/31579725492) 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
FAIL
```

I introduced the bug in the `Migrate()` method, but did not detect it locally because
the migrator's `Hash()` 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.0] - 2024-10-15

### *Breaking*: require go1.21.0+, drop support for go1.18, go1.19, go1.20
Expand Down Expand Up @@ -154,4 +206,4 @@ problems please report them and I'll do my best to fix them.
the shared VSCode settings to turn off this gopls analysis.

- Running `just tidy` updates all the `go.mod` files for the main library and
the migrators, but these should all be backwards-compatible changes.
the migrators, but these should all be backwards-compatible changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🧪 pgtestdb

![Latest Version](https://badgers.space/badge/latest%20version/v0.1.0/blueviolet?corner_radius=m)
![Latest Version](https://badgers.space/badge/latest%20version/v0.1.1/blueviolet?corner_radius=m)
![Golang](https://badgers.space/badge/golang/1.21+/blue?corner_radius=m)

pgtestdb is a golang library that helps you write efficient database-backed tests.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.0
v0.1.1
2 changes: 1 addition & 1 deletion migrators/atlasmigrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ replace github.com/peterldowns/pgtestdb => ../../

require (
github.com/jackc/pgx/v5 v5.7.1
github.com/peterldowns/pgtestdb v0.1.0
github.com/peterldowns/pgtestdb v0.1.1
github.com/peterldowns/testy v0.0.1
)

Expand Down
2 changes: 1 addition & 1 deletion migrators/bunmigrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.1
replace github.com/peterldowns/pgtestdb => ../../

require (
github.com/peterldowns/pgtestdb v0.1.0
github.com/peterldowns/pgtestdb v0.1.1
github.com/peterldowns/testy v0.0.1
github.com/uptrace/bun v1.2.1
github.com/uptrace/bun/dialect/pgdialect v1.2.1
Expand Down
2 changes: 1 addition & 1 deletion migrators/dbmatemigrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ replace github.com/peterldowns/pgtestdb => ../../
require (
github.com/amacneil/dbmate/v2 v2.4.0
github.com/jackc/pgx/v5 v5.7.1
github.com/peterldowns/pgtestdb v0.1.0
github.com/peterldowns/pgtestdb v0.1.1
github.com/peterldowns/testy v0.0.1
)

Expand Down
2 changes: 1 addition & 1 deletion migrators/golangmigrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ replace github.com/peterldowns/pgtestdb => ../../
require (
github.com/golang-migrate/migrate/v4 v4.16.0
github.com/jackc/pgx/v5 v5.7.1
github.com/peterldowns/pgtestdb v0.1.0
github.com/peterldowns/pgtestdb v0.1.1
github.com/peterldowns/testy v0.0.1
)

Expand Down
2 changes: 1 addition & 1 deletion migrators/goosemigrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ replace github.com/peterldowns/pgtestdb => ../../

require (
github.com/jackc/pgx/v5 v5.7.1
github.com/peterldowns/pgtestdb v0.1.0
github.com/peterldowns/pgtestdb v0.1.1
github.com/peterldowns/testy v0.0.1
github.com/pressly/goose/v3 v3.22.1
)
Expand Down
4 changes: 2 additions & 2 deletions migrators/goosemigrator/goose.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (gm *GooseMigrator) Migrate(
db *sql.DB,
_ pgtestdb.Config,
) error {
store, err := database.NewStore(database.DialectPostgres, goose.DefaultTablename)
store, err := database.NewStore(database.DialectPostgres, gm.TableName)
if err != nil {
return err
}
Expand All @@ -120,7 +120,7 @@ func (gm *GooseMigrator) Migrate(
if err != nil {
return err
}
provider, err := goose.NewProvider("postgres", db, migrationsDir, providerOptions...)
provider, err := goose.NewProvider("", db, migrationsDir, providerOptions...)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion migrators/pgmigrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ replace github.com/peterldowns/pgtestdb => ../../
require (
github.com/jackc/pgx/v5 v5.7.1
github.com/peterldowns/pgmigrate v0.0.5
github.com/peterldowns/pgtestdb v0.1.0
github.com/peterldowns/pgtestdb v0.1.1
github.com/peterldowns/testy v0.0.1
)

Expand Down
2 changes: 1 addition & 1 deletion migrators/sqlmigrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ replace github.com/peterldowns/pgtestdb => ../../

require (
github.com/jackc/pgx/v5 v5.7.1
github.com/peterldowns/pgtestdb v0.1.0
github.com/peterldowns/pgtestdb v0.1.1
github.com/peterldowns/testy v0.0.1
github.com/rubenv/sql-migrate v1.4.0
)
Expand Down
2 changes: 1 addition & 1 deletion migrators/ternmigrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ replace github.com/peterldowns/pgtestdb => ../../
require (
github.com/jackc/pgx/v5 v5.7.1
github.com/jackc/tern/v2 v2.2.1
github.com/peterldowns/pgtestdb v0.1.0
github.com/peterldowns/pgtestdb v0.1.1
github.com/peterldowns/testy v0.0.1
golang.org/x/net v0.28.0
)
Expand Down

0 comments on commit 29c5e55

Please sign in to comment.