golang-migrate / migrate

Database migrations. CLI and Golang library.
Other
14.99k stars 1.38k forks source link

Unclear about how exactly to use `pgx` driver #563

Open marcesher opened 3 years ago

marcesher commented 3 years ago

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!

dhui commented 3 years ago

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

bardawilpeter commented 2 years ago

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

krishi-saripalli commented 7 months ago

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"
page-fault-in-nonpaged-area commented 2 months ago

curious about this as well.