Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add driver for pgx v5 #848

Merged
merged 3 commits into from Apr 5, 2023
Merged

Add driver for pgx v5 #848

merged 3 commits into from Apr 5, 2023

Conversation

treuherz
Copy link
Contributor

@treuherz treuherz commented Nov 1, 2022

Fixes #827

  • Move existing driver into database/pgx/v4
  • Make exported items into database/pgx into links to database/pgx/v4,
    marked as Deprecated
  • Mark defunct ErrDatabaseDirty as Deprecated - no code returns it
  • Bump pgx/v4 dependency
  • Add test runs for newer Postgres versions

If you'd like the last couple of changes to be broken into a different PR then let me know.

@coveralls
Copy link

coveralls commented Nov 1, 2022

Coverage Status

Coverage: 58.526%. Remained the same when pulling 1ecd0a8 on treuherz:feature/pgxv5 into 8ec0422 on golang-migrate:master.

@koenbollen
Copy link

Hey! Quick bump from me? I'm currently running this branch to allow me to use pgx and golang-migrate together. (thanks btw!)

Any updates on getting this merged? 😇

@treuherz
Copy link
Contributor Author

Rebased on top of master

@mprimeaux
Copy link

Any updates on getting this merged? Appreciate everyone's time.

@pmorelli92
Copy link

Please some prio 🙏

@franchb
Copy link

franchb commented Feb 5, 2023

Any updates on this PR please?

vincentdaniel
vincentdaniel previously approved these changes Feb 15, 2023
@MNovruzov
Copy link

Any updates please???

@mprimeaux
Copy link

Hi @dhui. Would you mind reviewing and consider an approval? We have quite a few platforms waiting for this PR to be merged. Your help, and the help of any maintainer, is greatly appreciated.

@treuherz
Copy link
Contributor Author

Rebased on top of master again to fix conflicts, and bumped pgx minor versions again.

@vincentdaniel it was nice of you to approve this last time, but it didn't look like that granted mergeability, is that correct?

@vincentdaniel
Copy link

@treuherz correct, I am not maintainer of the project but I tried my luck anyway to see 🙈

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@treuherz thanks for the PR and apologies for the slow turnaround time. Life has been busy...

I'll also update golang-migrate to only support (and run tests for) Go 1.19 and 1.20

var (
multiStmtDelimiter = []byte(";")

DefaultMigrationsTable = "schema_migrations"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These would need to be exported as well.
I think it's safer and easier to leave the default as v4 (e.g. remove the v4 folder in this PR) and update the README and godocs to also mention that a v5 driver is also available. I think it's fine to offer both v4 and v5 so we can mark v4 as deprecated later. e.g. whenever pgx deprecates v4. Do you know if v4 has already been deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can do that.

Depends what you mean by deprecated. I think jackc is still applying critical bugfixes to v4 but it's not having significant work done.

@@ -0,0 +1,41 @@
# pgx

Backends are provided for [pgx v4](v4) and [pgx v5](v5). Links to v4 are exported in this package for backwards compatability.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be updated

@@ -4,5 +4,5 @@
package cli

import (
_ "github.com/golang-migrate/migrate/v4/database/pgx"
_ "github.com/golang-migrate/migrate/v4/database/pgx/v5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Fixes golang-migrate#827

- Move existing driver into database/pgx/v4
- Make exported items into database/pgx into links to database/pgx/v4,
  marked as Deprecated
- Remove most tests in database/pgx, leaving a couple of e2e tests
  behind to help ensure backwards compatibility.
- Mark defunct ErrDatabaseDirty as Deprecated - no code returns it
- Bump pgx/v4 dependency
- Add test runs for newer Postgres versions
@treuherz
Copy link
Contributor Author

treuherz commented Mar 17, 2023

Implemented comments, rebased on master again to resolve go.mod conflicts.

@treuherz treuherz requested a review from dhui March 17, 2023 17:07
Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@treuherz Thanks for the PR updates. This should be the last round.

README.md Outdated
@@ -24,7 +24,8 @@ Forked from [mattes/migrate](https://github.com/mattes/migrate)
Database drivers run migrations. [Add a new database?](database/driver.go)

* [PostgreSQL](database/postgres)
* [PGX](database/pgx)
* [PGX v4](database/pgx/v4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be database/pgx


func init() {
db := Postgres{}
database.Register("pgx", &db)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be registered as pgx5 to avoid a conflict with pgx (v4)

Copy link
Contributor Author

@treuherz treuherz Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of a few weeks ago, pgx registers its database/sql Driver under pgx/v4 or pgx/v5, as well as conditionally registering pgx if it’s not already registered by importing another version (see https://github.com/jackc/pgx/blob/9ae852eb583d2dced83b1d2ffe1c8803dda2c92e/stdlib/sql.go#L94). I’m happy to copy in the conflict-avoidance code or if you prefer just leave it out and have v4 register as pgx and pgx/v4, and v5 only register pgx/v5

I definitely think it would be better to match pgx’s pgx/vN registration string rather than inventing a new one. I know I didn’t use it in this PR originally but the upstream change is very new!

@@ -0,0 +1,8 @@
//go:build pgxv5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this file and tag to pgx5? The v is verbose and unnecessary.

Makefile Outdated
@@ -1,5 +1,5 @@
SOURCE ?= file go_bindata github github_ee bitbucket aws_s3 google_cloud_storage godoc_vfs gitlab
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgxv5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also need to update this to pgx5

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@treuherz Could you also update the db registration name?

@@ -28,6 +28,7 @@ import (
func init() {
db := Postgres{}
database.Register("pgx", &db)
database.Register("pgx/v4", &db)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register this as pgx4 since pgx/v4 is verbose. We don't need to be consistent with the upstream. Also, our DSN/connection string parsing uses URL parsing and / is not a valid scheme character

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -27,7 +27,7 @@ import (

func init() {
db := Postgres{}
database.Register("pgx", &db)
database.Register("pgx/v5", &db)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register as pgx5 for the same reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kriswill
Copy link

kriswill commented Apr 3, 2023

can we merge/release this?

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@treuherz Thanks again for the PR and for addressing my feedback!

@dhui dhui merged commit b94ed1a into golang-migrate:master Apr 5, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question: migrate or implement pgx v5 driver
10 participants