Browse Source
Merge pull request #358 from darigaaz86/main
feat: add postgres schema config support
pull/359/head
yedf2
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
15 additions and
2 deletions
-
client/dtmcli/dtmimp/types.go
-
client/dtmcli/dtmimp/utils.go
-
conf.sample.yml
-
dtmsvr/config/config.go
-
dtmsvr/config/config_test.go
-
dtmsvr/config/config_utils.go
|
|
|
@ -22,4 +22,5 @@ type DBConf struct { |
|
|
|
User string `yaml:"User"` |
|
|
|
Password string `yaml:"Password"` |
|
|
|
Db string `yaml:"Db"` |
|
|
|
Schema string `yaml:"Schema"` |
|
|
|
} |
|
|
|
|
|
|
|
@ -216,8 +216,8 @@ func GetDsn(conf DBConf) string { |
|
|
|
dsn := map[string]string{ |
|
|
|
"mysql": fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true&loc=Local&interpolateParams=true", |
|
|
|
conf.User, conf.Password, host, conf.Port, conf.Db), |
|
|
|
"postgres": fmt.Sprintf("host=%s user=%s password=%s dbname='%s' port=%d sslmode=disable", |
|
|
|
host, conf.User, conf.Password, conf.Db, conf.Port), |
|
|
|
"postgres": fmt.Sprintf("host=%s user=%s password=%s dbname='%s' search_path=%s port=%d sslmode=disable", |
|
|
|
host, conf.User, conf.Password, conf.Db, conf.Schema, conf.Port), |
|
|
|
}[driver] |
|
|
|
PanicIf(dsn == "", fmt.Errorf("unknow driver: %s", driver)) |
|
|
|
return dsn |
|
|
|
|
|
|
|
@ -26,6 +26,8 @@ |
|
|
|
# User: 'postgres' |
|
|
|
# Password: 'mysecretpassword' |
|
|
|
# Port: '5432' |
|
|
|
# Db: 'postgres' |
|
|
|
# Schema: 'myschema' |
|
|
|
|
|
|
|
### following config is for only Driver postgres/mysql |
|
|
|
# MaxOpenConns: 500 |
|
|
|
|
|
|
|
@ -54,6 +54,7 @@ type Store struct { |
|
|
|
User string `yaml:"User"` |
|
|
|
Password string `yaml:"Password"` |
|
|
|
Db string `yaml:"Db" default:"dtm"` |
|
|
|
Schema string `yaml:"Schema" default:"public"` |
|
|
|
MaxOpenConns int64 `yaml:"MaxOpenConns" default:"500"` |
|
|
|
MaxIdleConns int64 `yaml:"MaxIdleConns" default:"500"` |
|
|
|
ConnMaxLifeTime int64 `yaml:"ConnMaxLifeTime" default:"5"` |
|
|
|
@ -76,6 +77,7 @@ func (s *Store) GetDBConf() dtmcli.DBConf { |
|
|
|
User: s.User, |
|
|
|
Password: s.Password, |
|
|
|
Db: s.Db, |
|
|
|
Schema: s.Schema, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -52,6 +52,11 @@ func TestCheckConfig(t *testing.T) { |
|
|
|
userExpect := errors.New("Db user not valid ") |
|
|
|
assert.Equal(t, userErr, userExpect) |
|
|
|
|
|
|
|
conf.Store = Store{Driver: Postgres, Host: "127.0.0.1", Port: 8686, User: "postgres", Schema: ""} |
|
|
|
schemaErr := checkConfig(&conf) |
|
|
|
schemaExpect := errors.New("Postgres schema not valid") |
|
|
|
assert.Equal(t, schemaErr, schemaExpect) |
|
|
|
|
|
|
|
conf.Store = Store{Driver: Redis, Host: "", Port: 8686} |
|
|
|
assert.Equal(t, errors.New("Redis host not valid"), checkConfig(&conf)) |
|
|
|
|
|
|
|
|
|
|
|
@ -78,6 +78,9 @@ func checkConfig(conf *Type) error { |
|
|
|
if conf.Store.User == "" { |
|
|
|
return errors.New("Db user not valid ") |
|
|
|
} |
|
|
|
if conf.Store.Schema == "" { |
|
|
|
return errors.New("Postgres schema not valid") |
|
|
|
} |
|
|
|
case Redis: |
|
|
|
if conf.Store.Host == "" { |
|
|
|
return errors.New("Redis host not valid") |
|
|
|
|