mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00
add support for defining additonal database connection string args via extra_connection_string_args
This commit is contained in:
@ -221,6 +221,10 @@ func (ss *SqlStore) buildConnectionString() (string, error) {
|
|||||||
mysql.RegisterTLSConfig("custom", tlsCert)
|
mysql.RegisterTLSConfig("custom", tlsCert)
|
||||||
cnnstr += "&tls=custom"
|
cnnstr += "&tls=custom"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ss.dbCfg.ExtraConnectionStringArgs != "" {
|
||||||
|
cnnstr += "&" + ss.dbCfg.ExtraConnectionStringArgs
|
||||||
|
}
|
||||||
case migrator.POSTGRES:
|
case migrator.POSTGRES:
|
||||||
var host, port = "127.0.0.1", "5432"
|
var host, port = "127.0.0.1", "5432"
|
||||||
fields := strings.Split(ss.dbCfg.Host, ":")
|
fields := strings.Split(ss.dbCfg.Host, ":")
|
||||||
@ -237,6 +241,9 @@ func (ss *SqlStore) buildConnectionString() (string, error) {
|
|||||||
ss.dbCfg.User = "''"
|
ss.dbCfg.User = "''"
|
||||||
}
|
}
|
||||||
cnnstr = fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s sslcert=%s sslkey=%s sslrootcert=%s", ss.dbCfg.User, ss.dbCfg.Pwd, host, port, ss.dbCfg.Name, ss.dbCfg.SslMode, ss.dbCfg.ClientCertPath, ss.dbCfg.ClientKeyPath, ss.dbCfg.CaCertPath)
|
cnnstr = fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s sslcert=%s sslkey=%s sslrootcert=%s", ss.dbCfg.User, ss.dbCfg.Pwd, host, port, ss.dbCfg.Name, ss.dbCfg.SslMode, ss.dbCfg.ClientCertPath, ss.dbCfg.ClientKeyPath, ss.dbCfg.CaCertPath)
|
||||||
|
if ss.dbCfg.ExtraConnectionStringArgs != "" {
|
||||||
|
cnnstr += " " + ss.dbCfg.ExtraConnectionStringArgs
|
||||||
|
}
|
||||||
case migrator.SQLITE:
|
case migrator.SQLITE:
|
||||||
// special case for tests
|
// special case for tests
|
||||||
if !filepath.IsAbs(ss.dbCfg.Path) {
|
if !filepath.IsAbs(ss.dbCfg.Path) {
|
||||||
@ -244,6 +251,9 @@ func (ss *SqlStore) buildConnectionString() (string, error) {
|
|||||||
}
|
}
|
||||||
os.MkdirAll(path.Dir(ss.dbCfg.Path), os.ModePerm)
|
os.MkdirAll(path.Dir(ss.dbCfg.Path), os.ModePerm)
|
||||||
cnnstr = fmt.Sprintf("file:%s?cache=%s&mode=rwc", ss.dbCfg.Path, ss.dbCfg.CacheMode)
|
cnnstr = fmt.Sprintf("file:%s?cache=%s&mode=rwc", ss.dbCfg.Path, ss.dbCfg.CacheMode)
|
||||||
|
if ss.dbCfg.ExtraConnectionStringArgs != "" {
|
||||||
|
cnnstr += "&" + ss.dbCfg.ExtraConnectionStringArgs
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("Unknown database type: %s", ss.dbCfg.Type)
|
return "", fmt.Errorf("Unknown database type: %s", ss.dbCfg.Type)
|
||||||
}
|
}
|
||||||
@ -321,6 +331,8 @@ func (ss *SqlStore) readConfig() {
|
|||||||
ss.dbCfg.Path = sec.Key("path").MustString("data/grafana.db")
|
ss.dbCfg.Path = sec.Key("path").MustString("data/grafana.db")
|
||||||
|
|
||||||
ss.dbCfg.CacheMode = sec.Key("cache_mode").MustString("private")
|
ss.dbCfg.CacheMode = sec.Key("cache_mode").MustString("private")
|
||||||
|
|
||||||
|
ss.dbCfg.ExtraConnectionStringArgs = sec.Key("extra_connection_string_args").String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitTestDB(t *testing.T) *SqlStore {
|
func InitTestDB(t *testing.T) *SqlStore {
|
||||||
@ -409,4 +421,5 @@ type DatabaseConfig struct {
|
|||||||
MaxIdleConn int
|
MaxIdleConn int
|
||||||
ConnMaxLifetime int
|
ConnMaxLifetime int
|
||||||
CacheMode string
|
CacheMode string
|
||||||
|
ExtraConnectionStringArgs string
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user