Skip to content

Commit

Permalink
test: add test for Go migrate sample (#2336)
Browse files Browse the repository at this point in the history
Adds tests and a README for Golang Migrate.
  • Loading branch information
olavloite authored Sep 19, 2024
1 parent 5ac3255 commit c310ce8
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/samples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- name: Run pgx Sample tests
working-directory: ./samples/golang/pgx
run: go test
- name: Run migrate Sample tests
working-directory: ./samples/golang/migrate
run: go test
python-samples:
runs-on: ubuntu-latest
steps:
Expand Down
16 changes: 16 additions & 0 deletions samples/golang/migrate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Golang Migrate

This sample application shows how to use [Golang Migrate](https://github.com/golang-migrate/migrate)
with PGAdapter. The sample application automatically starts PGAdapter and the Spanner emulator in a
Docker container and connects to this. It then executes a small set of migration scripts.

__NOTE__: Golang Migrate only works with PGAdapter if you add `fallback_application_name=golang-migrate`
to the connection string. See [sample.go](./sample.go) for a full example.

```go
connString := "postgres://localhost:5432/my-database?sslmode=disable&fallback_application_name=golang-migrate"
m, err := migrate.New("file://migrations", connString)
```

If you fail to add the application name to the connection string, you will get an error that
the function `pg_advisory_lock` is not supported.
57 changes: 50 additions & 7 deletions samples/golang/migrate/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,61 @@ module migrate

go 1.22.3

require github.com/golang-migrate/migrate/v4 v4.18.1
require (
github.com/GoogleCloudPlatform/pgadapter/wrappers/golang v0.0.0-20240918132525-a4dc9268921f
github.com/golang-migrate/migrate/v4 v4.18.1
)

require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-github/v39 v39.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.2.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/testcontainers/testcontainers-go v0.33.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.25.0 // indirect
)
Loading

0 comments on commit c310ce8

Please sign in to comment.