migrate icon indicating copy to clipboard operation
migrate copied to clipboard

Unclear about how exactly to use `pgx` driver

Open marcesher opened this issue 4 years ago • 5 comments

Describe the Bug I am trying to follow the documentation to use go-migrate with pgx and I'm having trouble. I'm not sure if I'm reading the docs incorrectly, if there's a documentation bug, an actual bug, or something else.

Steps to Reproduce Steps to reproduce the behavior:

  1. According to https://github.com/golang-migrate/migrate/tree/master/cmd/migrate, the driver tag to install is the name of the database being used in databases. I infer from this that if I'm using pgx, then I should use go install -tags 'pgx' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
  2. According to https://github.com/golang-migrate/migrate/tree/master/database/pgx the connect string is prefixed with pgx://

So I ran go install -tags 'pgx' github.com/golang-migrate/migrate/v4/cmd/migrate@latest, and then when I run migrate in the drivers output it just shows stub

When I try running a migration against a DB connect string prefixed with pgx it says that the pgx driver isn't installed

I then tried go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest, then used a postgres:// connect string, and it errored with an SSL error, and it is clearly trying to use pq

I then suffixed the connect string with ?sslmode=disable

And the migrations worked.

Now, with using postgres and sslmode=disable I'm not sure if it's an actual problem that my app is using pgx but migrations are using postgres. I've only tried simple migrations to date, nothing that uses anything postgres-specific such as JSON fields.

Expected Behavior Based on the docs, I'd expect to use go install -tags 'pgx'... and a connect string with pgx

Migrate Version dev

Loaded Source Drivers e.g. s3, github, go-bindata, gcs, file Obtained by running: migrate -help

Loaded Database Drivers file

Go Version go version go1.16.3 linux/amd64

Stacktrace None

Thanks for any help!

marcesher avatar May 14 '21 17:05 marcesher

You'll need to use go install -tags 'pgx' github.com/golang-migrate/migrate/v4/cmd/migrate@master since the latest release doesn't support pgx yet

dhui avatar May 15 '21 03:05 dhui

When do we think this will be added to the new release?

bardawilpeter avatar Jan 31 '22 17:01 bardawilpeter

Any fix this? I stll don't know if I should be using pgx://. I'm still getting Migration creation failed: database driver: unknown driver pgx (forgotten import?)

My imports are here:

"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/pgx/v5"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/jackc/pgx/v5"

krishi-saripalli avatar Jan 23 '24 01:01 krishi-saripalli