added postgres configuration option to choose the schema(#4318)

This commit is contained in:
gezimbll
2024-04-16 06:06:14 -04:00
committed by Dan Christian Bogos
parent 863f837bd2
commit cf720b0618
10 changed files with 20 additions and 5 deletions

View File

@@ -28,7 +28,7 @@ import (
)
// NewPostgresStorage returns the posgres storDB
func NewPostgresStorage(host, port, name, user, password, sslmode string, maxConn, maxIdleConn int, connMaxLifetime time.Duration) (*SQLStorage, error) {
func NewPostgresStorage(host, port, name, user, password, sslmode, pgSchema string, maxConn, maxIdleConn int, connMaxLifetime time.Duration) (*SQLStorage, error) {
connectString := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s sslmode=%s", host, port, name, user, password, sslmode)
db, err := gorm.Open(postgres.Open(connectString), &gorm.Config{AllowGlobalUpdate: true})
if err != nil {
@@ -41,6 +41,9 @@ func NewPostgresStorage(host, port, name, user, password, sslmode string, maxCon
if err = postgressStorage.Db.Ping(); err != nil {
return nil, err
}
if pgSchema != "" {
postgressStorage.Db.Exec(fmt.Sprintf("set search_path='%s'", pgSchema))
}
postgressStorage.Db.SetMaxIdleConns(maxIdleConn)
postgressStorage.Db.SetMaxOpenConns(maxConn)
postgressStorage.Db.SetConnMaxLifetime(connMaxLifetime)