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 Oct 30, 2024
1 parent b38eaf8 commit 391d10f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion engine/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,22 @@ 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)
}
fmt.Println(dsn)
return dsn
}

Expand Down

0 comments on commit 391d10f

Please sign in to comment.