migrate
migrate copied to clipboard
Unclear about how exactly to use `pgx` driver
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:
- According to https://github.com/golang-migrate/migrate/tree/master/cmd/migrate, the driver
tagto install is the name of the database being used indatabases. I infer from this that if I'm using pgx, then I should usego install -tags 'pgx' github.com/golang-migrate/migrate/v4/cmd/migrate@latest - 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!
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
When do we think this will be added to the new release?
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"