From 08457cd665cc25365ef728716c911db86eb98cf2 Mon Sep 17 00:00:00 2001 From: shimonp21 Date: Fri, 24 Jun 2022 12:16:42 +0200 Subject: [PATCH] fix: Issues when PG username is 'cloudquery' Before this fix, cloudquery misbehaved when the PG username was named 'cloudquery'. It created tables in the 'cloudquery' schema instead of the 'public' schema. This happened because the search path was '"$user", public', which means it depended on the username. This fix, upon connection to PG, will change serach_path to 'public' only, i.e. not dependent on username (which is way more predictable). This won't impact us explicitly accessing the 'cloudquery' schema via 'cloudquery.', which is what we do when we actually need the 'cloudquery' schema. --- database/postgres/connection.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/database/postgres/connection.go b/database/postgres/connection.go index 57a5c8a8..9258afeb 100644 --- a/database/postgres/connection.go +++ b/database/postgres/connection.go @@ -16,6 +16,11 @@ func Connect(ctx context.Context, dsnURI string) (*pgxpool.Pool, error) { return nil, dsn.RedactParseError(err) } poolCfg.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error { + _, err := conn.Exec(ctx, "SET search_path=public") + if err != nil { + return err + } + UUIDType := pgtype.DataType{ Value: &UUID{}, Name: "uuid",