Skip to content

Commit 2a10c3b

Browse files
author
Gregoire Salingue
committed
fix: schema selection at connection time
Signed-off-by: Gregoire Salingue <[email protected]>
1 parent b38eaf8 commit 2a10c3b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

engine/database/database.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,20 @@ func Init(ctx context.Context, dbConfig DBConfiguration) (*DBConnectionFactory,
187187
}
188188
}
189189

190+
if f.DBSchema != "public" {
191+
if _, err := f.Database.Exec(fmt.Sprintf("SET search_path = %s", f.DBSchema)); err != nil {
192+
log.Error(ctx, "unable to set search_path with %s on database: %s", f.DBSchema, err)
193+
return nil, sdk.WrapError(err, "unable to set search_path with %s", f.DBSchema)
194+
}
195+
}
196+
190197
return f, nil
191198
}
192199

193200
func (f *DBConnectionFactory) dsn() string {
194201
dsn := fmt.Sprintf("user=%s password='%s' dbname=%s host=%s port=%d sslmode=%s connect_timeout=%d", f.DBUser, f.DBPassword, f.DBName, f.DBHost, f.DBPort, f.DBSSLMode, f.DBConnectTimeout)
195202
if f.DBSchema != "public" {
196-
dsn += fmt.Sprintf(" search_path=%s", f.DBSchema)
203+
dsn += fmt.Sprintf(" options='-csearch_path=%s'", f.DBSchema)
197204
}
198205
return dsn
199206
}

0 commit comments

Comments
 (0)