Skip to content

Commit c344f0b

Browse files
committed
Remove lib/pq usage and rely on pgtype arrays
1 parent 9966185 commit c344f0b

File tree

4 files changed

+86
-38
lines changed

4 files changed

+86
-38
lines changed

cmd/pg-schema-diff/flags.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ type connectionFlags struct {
1414
dsn string
1515
dsnFlagName string
1616

17-
// isEmptyDsnUsingPq indicates to connect via DSN using the pq environment variables and defaults.
18-
isEmptyDsnUsingPq bool
19-
isEmptyDsnUsingPqFlagName string
17+
// useEmptyDsn indicates to connect via DSN using the libpq-compatible environment variables and defaults.
18+
useEmptyDsn bool
19+
useEmptyDsnFlagName string
2020
}
2121

2222
func createConnectionFlags(cmd *cobra.Command, prefix string, additionalHelp string) *connectionFlags {
@@ -29,23 +29,23 @@ func createConnectionFlags(cmd *cobra.Command, prefix string, additionalHelp str
2929
}
3030
cmd.Flags().StringVar(&c.dsn, c.dsnFlagName, "", dsnFlagHelp)
3131

32-
c.isEmptyDsnUsingPqFlagName = prefix + "empty-dsn"
33-
isEmptyDsnUsingPqFlagHelp := "Connect with an empty DSN using the pq environment variables and defaults."
32+
c.useEmptyDsnFlagName = prefix + "empty-dsn"
33+
useEmptyDsnFlagHelp := "Connect with an empty DSN using the libpq-compatible environment variables and defaults."
3434
if additionalHelp != "" {
35-
isEmptyDsnUsingPqFlagHelp += " " + additionalHelp
35+
useEmptyDsnFlagHelp += " " + additionalHelp
3636
}
37-
cmd.Flags().BoolVar(&c.isEmptyDsnUsingPq, c.isEmptyDsnUsingPqFlagName, false, isEmptyDsnUsingPqFlagHelp)
37+
cmd.Flags().BoolVar(&c.useEmptyDsn, c.useEmptyDsnFlagName, false, useEmptyDsnFlagHelp)
3838

3939
return &c
4040
}
4141

4242
func (c *connectionFlags) IsSet() bool {
43-
return c.dsn != "" || c.isEmptyDsnUsingPq
43+
return c.dsn != "" || c.useEmptyDsn
4444
}
4545

4646
func parseConnectionFlags(flags *connectionFlags) (*pgx.ConnConfig, error) {
47-
if !flags.isEmptyDsnUsingPq && flags.dsn == "" {
48-
return nil, fmt.Errorf("must specify either --%s or --%s", flags.dsnFlagName, flags.isEmptyDsnUsingPqFlagName)
47+
if !flags.useEmptyDsn && flags.dsn == "" {
48+
return nil, fmt.Errorf("must specify either --%s or --%s", flags.dsnFlagName, flags.useEmptyDsnFlagName)
4949
}
5050
connConfig, err := pgx.ParseConfig(flags.dsn)
5151
if err != nil {

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ require (
77
github.com/google/go-cmp v0.5.9
88
github.com/google/uuid v1.3.0
99
github.com/hashicorp/go-version v1.7.0
10+
github.com/jackc/pgtype v1.14.0
1011
github.com/jackc/pgx/v4 v4.18.2
1112
github.com/kr/pretty v0.3.1
12-
github.com/lib/pq v1.10.2
1313
github.com/manifoldco/promptui v0.9.0
1414
github.com/mitchellh/hashstructure/v2 v2.0.2
1515
github.com/spf13/cobra v1.7.0
@@ -27,7 +27,6 @@ require (
2727
github.com/jackc/pgpassfile v1.0.0 // indirect
2828
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
2929
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
30-
github.com/jackc/pgtype v1.14.0 // indirect
3130
github.com/kr/text v0.2.0 // indirect
3231
github.com/pmezard/go-difflib v1.0.0 // indirect
3332
github.com/rogpeppe/go-internal v1.9.0 // indirect

internal/queries/queries.sql

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,9 @@ SELECT
529529
INNER JOIN
530530
pg_catalog.pg_namespace AS dep_ns
531531
ON dep_c.relnamespace = dep_ns.oid
532-
-- Cast to text because pgv4/pq does not support unmarshalling JSON
533-
-- arrays into []json.RawMessage.
534-
-- Instead, they must be unmarshalled as string arrays.
535-
-- https://github.com/lib/pq/pull/466
532+
-- Cast to text because our database/sql driver does not support unmarshalling
533+
-- JSON arrays into []json.RawMessage. Instead, they must be unmarshalled as
534+
-- string arrays.
536535
WHERE d.refobjid = c.oid)::TEXT [] AS table_dependencies,
537536
PG_GET_VIEWDEF(c.oid, true) AS view_definition
538537
FROM pg_catalog.pg_class AS c
@@ -600,10 +599,9 @@ SELECT
600599
INNER JOIN
601600
pg_catalog.pg_namespace AS dep_ns
602601
ON dep_c.relnamespace = dep_ns.oid
603-
-- Cast to text because pgv4/pq does not support unmarshalling JSON
604-
-- arrays into []json.RawMessage.
605-
-- Instead, they must be unmarshalled as string arrays.
606-
-- https://github.com/lib/pq/pull/466
602+
-- Cast to text because our database/sql driver does not support unmarshalling
603+
-- JSON arrays into []json.RawMessage. Instead, they must be unmarshalled as
604+
-- string arrays.
607605
WHERE d.refobjid = c.oid)::TEXT [] AS table_dependencies,
608606
PG_GET_VIEWDEF(c.oid, true) AS view_definition
609607
FROM pg_catalog.pg_class AS c

internal/queries/queries.sql.go

Lines changed: 69 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)