Skip to content

Commit

Permalink
fix: schema selection at connection time
Browse files Browse the repository at this point in the history
Signed-off-by: Gregoire Salingue <[email protected]>
  • Loading branch information
Gregoire Salingue committed Nov 1, 2024
1 parent b38eaf8 commit 2a10c3b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion engine/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,20 @@ func Init(ctx context.Context, dbConfig DBConfiguration) (*DBConnectionFactory,
}
}

if f.DBSchema != "public" {
if _, err := f.Database.Exec(fmt.Sprintf("SET search_path = %s", f.DBSchema)); err != nil {
log.Error(ctx, "unable to set search_path with %s on database: %s", f.DBSchema, err)
return nil, sdk.WrapError(err, "unable to set search_path with %s", f.DBSchema)
}
}

return f, nil
}

func (f *DBConnectionFactory) dsn() string {
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)
if f.DBSchema != "public" {
dsn += fmt.Sprintf(" search_path=%s", f.DBSchema)
dsn += fmt.Sprintf(" options='-csearch_path=%s'", f.DBSchema)
}
return dsn
}
Expand Down

0 comments on commit 2a10c3b

Please sign in to comment.