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

Commit

Permalink
fix: Optional forced search_path (#415)
Browse files Browse the repository at this point in the history
Co-authored-by: Kemal Hadimli <[email protected]>
  • Loading branch information
disq and disq authored Jul 8, 2022
1 parent fdf97ac commit 89d6b92
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions database/postgres/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package postgres

import (
"context"
"strings"

"github.com/cloudquery/cq-provider-sdk/database/dsn"
"github.com/jackc/pgtype"
Expand All @@ -16,9 +17,12 @@ 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
// force a known search_path if DSN doesn't specify one
if !strings.Contains(dsnURI, "&search_path=") && !strings.Contains(dsnURI, "?search_path=") {
_, err := conn.Exec(ctx, "SET search_path=public")
if err != nil {
return err
}
}

UUIDType := pgtype.DataType{
Expand Down

0 comments on commit 89d6b92

Please sign in to comment.