@@ -119,9 +119,10 @@ func (u *DatabaseService) CheckDatabase(req dto.DatabaseCreate) bool {
119119 if req .Timeout == 0 {
120120 req .Timeout = 30
121121 }
122+ var err error
122123 switch req .Type {
123124 case constant .AppPostgresql :
124- _ , err : = postgresql .NewPostgresqlClient (pgclient.DBInfo {
125+ _ , err = postgresql .NewPostgresqlClient (pgclient.DBInfo {
125126 From : "remote" ,
126127 Address : req .Address ,
127128 Port : req .Port ,
@@ -130,17 +131,15 @@ func (u *DatabaseService) CheckDatabase(req dto.DatabaseCreate) bool {
130131 Password : req .Password ,
131132 Timeout : req .Timeout ,
132133 })
133- return err == nil
134134 case constant .AppRedis :
135- _ , err : = redisclient .NewRedisClient (redisclient.DBInfo {
135+ _ , err = redisclient .NewRedisClient (redisclient.DBInfo {
136136 Address : req .Address ,
137137 Port : req .Port ,
138138 Password : req .Password ,
139139 Timeout : req .Timeout ,
140140 })
141- return err == nil
142141 case "mysql" , "mariadb" :
143- _ , err : = mysql .NewMysqlClient (client.DBInfo {
142+ _ , err = mysql .NewMysqlClient (client.DBInfo {
144143 From : "remote" ,
145144 Address : req .Address ,
146145 Port : req .Port ,
@@ -154,10 +153,13 @@ func (u *DatabaseService) CheckDatabase(req dto.DatabaseCreate) bool {
154153 SkipVerify : req .SkipVerify ,
155154 Timeout : req .Timeout ,
156155 })
157- return err == nil
156+ }
157+ if err != nil {
158+ global .LOG .Errorf ("check database connection failed, err: %v" , err )
159+ return false
158160 }
159161
160- return false
162+ return true
161163}
162164
163165func (u * DatabaseService ) Create (req dto.DatabaseCreate ) error {
@@ -174,12 +176,13 @@ func (u *DatabaseService) Create(req dto.DatabaseCreate) error {
174176 switch req .Type {
175177 case constant .AppPostgresql :
176178 if _ , err := postgresql .NewPostgresqlClient (pgclient.DBInfo {
177- From : "remote" ,
178- Address : req .Address ,
179- Port : req .Port ,
180- Username : req .Username ,
181- Password : req .Password ,
182- Timeout : req .Timeout ,
179+ From : "remote" ,
180+ Address : req .Address ,
181+ Port : req .Port ,
182+ InitialDB : req .InitialDB ,
183+ Username : req .Username ,
184+ Password : req .Password ,
185+ Timeout : req .Timeout ,
183186 }); err != nil {
184187 return err
185188 }
@@ -275,12 +278,13 @@ func (u *DatabaseService) Update(req dto.DatabaseUpdate) error {
275278 switch req .Type {
276279 case constant .AppPostgresql :
277280 if _ , err := postgresql .NewPostgresqlClient (pgclient.DBInfo {
278- From : "remote" ,
279- Address : req .Address ,
280- Port : req .Port ,
281- Username : req .Username ,
282- Password : req .Password ,
283- Timeout : req .Timeout ,
281+ From : "remote" ,
282+ Address : req .Address ,
283+ Port : req .Port ,
284+ InitialDB : req .InitialDB ,
285+ Username : req .Username ,
286+ Password : req .Password ,
287+ Timeout : req .Timeout ,
284288 }); err != nil {
285289 return err
286290 }
@@ -326,6 +330,7 @@ func (u *DatabaseService) Update(req dto.DatabaseUpdate) error {
326330 upMap ["port" ] = req .Port
327331 upMap ["username" ] = req .Username
328332 upMap ["password" ] = pass
333+ upMap ["initial_db" ] = req .InitialDB
329334 upMap ["timeout" ] = req .Timeout
330335 upMap ["description" ] = req .Description
331336 upMap ["ssl" ] = req .SSL
0 commit comments