@@ -80,10 +80,13 @@ func GetDatabaseListQuery(username string) string {
8080}
8181
8282// CheckSource checks the readiness of the source database to dump and restore processes.
83- func CheckSource (ctx context.Context , conf * models.ConnectionTest , imageContent * ImageContent ) (* models.TestConnection , error ) {
83+ func CheckSource (ctx context.Context , conf * models.ConnectionTest , imageContent * ImageContent ) (* models.DBSource , error ) {
84+ dbSource := & models.DBSource {}
85+
8486 conn , tcResponse := checkConnection (ctx , conf , conf .DBName )
8587 if tcResponse != nil {
86- return tcResponse , nil
88+ dbSource .TestConnection = tcResponse
89+ return dbSource , nil
8790 }
8891
8992 defer func () {
@@ -92,12 +95,43 @@ func CheckSource(ctx context.Context, conf *models.ConnectionTest, imageContent
9295 }
9396 }()
9497
98+ // Return the database version in any case.
99+ dbVersion , err := getMajorVersion (ctx , conn )
100+ if err != nil {
101+ return nil , err
102+ }
103+
104+ dbSource .DBVersion = dbVersion
105+
106+ tcResponse = & models.TestConnection {
107+ Status : models .TCStatusOK ,
108+ Result : models .TCResultOK ,
109+ Message : models .TCMessageOK ,
110+ }
111+
112+ dbSource .TestConnection = tcResponse
113+
114+ tuningParameters , err := getTuningParameters (ctx , conn )
115+ if err != nil {
116+ dbSource .Status = models .TCStatusError
117+ dbSource .Result = models .TCResultQueryError
118+ dbSource .Message = err .Error ()
119+
120+ return dbSource , err
121+ }
122+
123+ dbSource .TuningParams = tuningParameters
124+
95125 dbList := conf .DBList
96126
97127 if len (dbList ) == 0 {
98128 dbSourceList , err := getDBList (ctx , conn , conf .Username )
99129 if err != nil {
100- return nil , err
130+ dbSource .Status = models .TCStatusError
131+ dbSource .Result = models .TCResultQueryError
132+ dbSource .Message = err .Error ()
133+
134+ return dbSource , err
101135 }
102136
103137 dbList = dbSourceList
@@ -111,45 +145,32 @@ func CheckSource(ctx context.Context, conf *models.ConnectionTest, imageContent
111145 Message : "Too many databases were requested to be checked. Only the following databases have been verified: " +
112146 strings .Join (dbList , ", " ),
113147 }
148+ dbSource .TestConnection = tcResponse
114149 }
115150
116151 for _ , dbName := range dbList {
117152 dbConn , listTC := checkConnection (ctx , conf , dbName )
118153 if listTC != nil {
119- return listTC , nil
154+ dbSource .TestConnection = listTC
155+ return dbSource , nil
120156 }
121157
122158 listTC , err := checkContent (ctx , dbConn , dbName , imageContent )
123159 if err != nil {
124- return nil , err
160+ dbSource .Status = models .TCStatusError
161+ dbSource .Result = models .TCResultQueryError
162+ dbSource .Message = err .Error ()
163+
164+ return dbSource , err
125165 }
126166
127167 if listTC != nil {
128- return listTC , nil
168+ dbSource .TestConnection = listTC
169+ return dbSource , nil
129170 }
130171 }
131172
132- if tcResponse != nil {
133- return tcResponse , nil
134- }
135-
136- dbVersion , err := getMajorVersion (ctx , conn )
137- if err != nil {
138- return nil , err
139- }
140-
141- tuningParameters , err := getTuningParameters (ctx , conn )
142- if err != nil {
143- return nil , err
144- }
145-
146- return & models.TestConnection {
147- Status : models .TCStatusOK ,
148- Result : models .TCResultOK ,
149- Message : models .TCMessageOK ,
150- DBVersion : dbVersion ,
151- TuningParams : tuningParameters ,
152- }, nil
173+ return dbSource , nil
153174}
154175
155176func getDBList (ctx context.Context , conn * pgx.Conn , dbUsername string ) ([]string , error ) {
0 commit comments