Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cmd/pg-schema-diff/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type connectionFlags struct {
dsn string
dsnFlagName string

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

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

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

return &c
}

func (c *connectionFlags) IsSet() bool {
return c.dsn != "" || c.isEmptyDsnUsingPq
return c.dsn != "" || c.useEmptyDsn
}

func parseConnectionFlags(flags *connectionFlags) (*pgx.ConnConfig, error) {
if !flags.isEmptyDsnUsingPq && flags.dsn == "" {
return nil, fmt.Errorf("must specify either --%s or --%s", flags.dsnFlagName, flags.isEmptyDsnUsingPqFlagName)
if !flags.useEmptyDsn && flags.dsn == "" {
return nil, fmt.Errorf("must specify either --%s or --%s", flags.dsnFlagName, flags.useEmptyDsnFlagName)
}
connConfig, err := pgx.ParseConfig(flags.dsn)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/hashicorp/go-version v1.7.0
github.com/jackc/pgtype v1.14.0
github.com/jackc/pgx/v4 v4.18.2
github.com/kr/pretty v0.3.1
github.com/lib/pq v1.10.2
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/hashstructure/v2 v2.0.2
github.com/spf13/cobra v1.7.0
Expand All @@ -27,7 +27,6 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
Expand Down
14 changes: 6 additions & 8 deletions internal/queries/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,9 @@ SELECT
INNER JOIN
pg_catalog.pg_namespace AS dep_ns
ON dep_c.relnamespace = dep_ns.oid
-- Cast to text because pgv4/pq does not support unmarshalling JSON
-- arrays into []json.RawMessage.
-- Instead, they must be unmarshalled as string arrays.
-- https://github.com/lib/pq/pull/466
-- Cast to text because our database/sql driver does not support unmarshalling
-- JSON arrays into []json.RawMessage. Instead, they must be unmarshalled as
-- string arrays.
WHERE d.refobjid = c.oid)::TEXT [] AS table_dependencies,
PG_GET_VIEWDEF(c.oid, true) AS view_definition
FROM pg_catalog.pg_class AS c
Expand Down Expand Up @@ -600,10 +599,9 @@ SELECT
INNER JOIN
pg_catalog.pg_namespace AS dep_ns
ON dep_c.relnamespace = dep_ns.oid
-- Cast to text because pgv4/pq does not support unmarshalling JSON
-- arrays into []json.RawMessage.
-- Instead, they must be unmarshalled as string arrays.
-- https://github.com/lib/pq/pull/466
-- Cast to text because our database/sql driver does not support unmarshalling
-- JSON arrays into []json.RawMessage. Instead, they must be unmarshalled as
-- string arrays.
WHERE d.refobjid = c.oid)::TEXT [] AS table_dependencies,
PG_GET_VIEWDEF(c.oid, true) AS view_definition
FROM pg_catalog.pg_class AS c
Expand Down
87 changes: 69 additions & 18 deletions internal/queries/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading