mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
added postgres configuration option to choose the schema(#4318)
This commit is contained in:
committed by
Dan Christian Bogos
parent
863f837bd2
commit
cf720b0618
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user