Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
postgres: switch from lib/pq to jackc/pgx (pressly#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Pastro authored Jul 10, 2022
1 parent 7792d04 commit bc72e78
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/goose/driver_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
package main

import (
_ "github.com/lib/pq"
_ "github.com/jackc/pgx/v4/stdlib"
)
12 changes: 7 additions & 5 deletions cmd/goose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ func main() {
}

driver, dbstring, command := args[0], args[1], args[2]
// To avoid breaking existing consumers, treat sqlite3 as sqlite.
// An implementation detail that consumers should not care which
// underlying driver is used. Internally uses the CGo-free port
// of SQLite: modernc.org/sqlite
if driver == "sqlite3" {
// To avoid breaking existing consumers. An implementation detail
// that consumers should not care which underlying driver is used.
switch driver {
case "sqlite3":
// Internally uses the CGo-free port of SQLite: modernc.org/sqlite
driver = "sqlite"
case "postgres":
driver = "pgx"
}
db, err := goose.OpenDBWithDriver(driver, normalizeDBString(driver, dbstring, *certfile, *sslcert, *sslkey))
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/avast/retry-go/v4 v4.1.0
github.com/denisenkom/go-mssqldb v0.12.2
github.com/go-sql-driver/mysql v1.6.0
github.com/lib/pq v1.10.6
github.com/jackc/pgx/v4 v4.16.1
github.com/ory/dockertest/v3 v3.9.1
github.com/ziutek/mymysql v1.5.4
modernc.org/sqlite v1.17.3
Expand All @@ -29,7 +29,15 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.12.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.11.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lib/pq v1.10.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 // indirect
Expand All @@ -47,10 +55,11 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
139 changes: 137 additions & 2 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions internal/testdb/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"time"

_ "github.com/go-sql-driver/mysql"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
)
Expand Down
3 changes: 2 additions & 1 deletion internal/testdb/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"strconv"

_ "github.com/jackc/pgx/v4/stdlib"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
)
Expand Down Expand Up @@ -80,7 +81,7 @@ func newPostgres(opts ...OptionsFunc) (*sql.DB, func(), error) {
if err := pool.Retry(
func() error {
var err error
db, err = sql.Open("postgres", psqlInfo)
db, err = sql.Open("pgx", psqlInfo)
if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"syscall"
"testing"

_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"github.com/pressly/goose/v3/internal/check"
"github.com/pressly/goose/v3/internal/testdb"
)
Expand Down

0 comments on commit bc72e78

Please sign in to comment.