Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit b542dc1

Browse files
committed
common, cypress: Change our PG library to jackc/pgx/v5
We've been using v3 so far, which was working well, however its not supported by golang-migrate. Initial impression of this new version is that it seems needlessly complex. Although there's some documentation, there doesn't seem to be much in the way of useful examples. There are no upgrade docs (eg "these new types replace the old ones..."), nor release notes (not even for major versions), etc. :/ So, this is definitely a "change", rather than an "upgrade".
1 parent 2454233 commit b542dc1

File tree

6 files changed

+368
-378
lines changed

6 files changed

+368
-378
lines changed

common/config.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strconv"
1010

1111
"github.com/BurntSushi/toml"
12-
"github.com/jackc/pgx"
12+
"github.com/jackc/pgx/v5/pgxpool"
1313
"github.com/mitchellh/go-homedir"
1414
)
1515

@@ -18,7 +18,7 @@ var (
1818
Conf TomlConfig
1919

2020
// PostgreSQL configuration info
21-
pgConfig = new(pgx.ConnConfig)
21+
pgConfig *pgxpool.Config
2222
)
2323

2424
// ReadConfig reads the server configuration file.
@@ -172,12 +172,9 @@ func ReadConfig() error {
172172
}
173173
}
174174

175+
175176
// Set the PostgreSQL configuration values
176-
pgConfig.Host = Conf.Pg.Server
177-
pgConfig.Port = uint16(Conf.Pg.Port)
178-
pgConfig.User = Conf.Pg.Username
179-
pgConfig.Password = Conf.Pg.Password
180-
pgConfig.Database = Conf.Pg.Database
177+
pgConfig, err = pgxpool.ParseConfig(fmt.Sprintf("host=%s port=%d user= %s password = %s dbname=%s pool_max_conns=%d connect_timeout=10", Conf.Pg.Server, uint16(Conf.Pg.Port), Conf.Pg.Username, Conf.Pg.Password, Conf.Pg.Database, Conf.Pg.NumConnections))
181178
clientTLSConfig := tls.Config{}
182179
if Conf.Environment.Environment == "production" {
183180
clientTLSConfig.ServerName = Conf.Pg.Server
@@ -186,13 +183,11 @@ func ReadConfig() error {
186183
clientTLSConfig.InsecureSkipVerify = true
187184
}
188185
if Conf.Pg.SSL {
189-
pgConfig.TLSConfig = &clientTLSConfig
186+
pgConfig.ConnConfig.TLSConfig = &clientTLSConfig
190187
} else {
191-
pgConfig.TLSConfig = nil
188+
pgConfig.ConnConfig.TLSConfig = nil
192189
}
193190

194-
// TODO: Add environment variable overrides for memcached
195-
196191
// Environment variable override for non-production logged-in user
197192
tempString = os.Getenv("DBHUB_USERNAME")
198193
if tempString != "" {

0 commit comments

Comments
 (0)