@@ -80,10 +80,13 @@ func GetDatabaseListQuery(username string) string {
80
80
}
81
81
82
82
// 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
+
84
86
conn , tcResponse := checkConnection (ctx , conf , conf .DBName )
85
87
if tcResponse != nil {
86
- return tcResponse , nil
88
+ dbSource .TestConnection = tcResponse
89
+ return dbSource , nil
87
90
}
88
91
89
92
defer func () {
@@ -92,12 +95,43 @@ func CheckSource(ctx context.Context, conf *models.ConnectionTest, imageContent
92
95
}
93
96
}()
94
97
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
+
95
125
dbList := conf .DBList
96
126
97
127
if len (dbList ) == 0 {
98
128
dbSourceList , err := getDBList (ctx , conn , conf .Username )
99
129
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
101
135
}
102
136
103
137
dbList = dbSourceList
@@ -111,45 +145,32 @@ func CheckSource(ctx context.Context, conf *models.ConnectionTest, imageContent
111
145
Message : "Too many databases were requested to be checked. Only the following databases have been verified: " +
112
146
strings .Join (dbList , ", " ),
113
147
}
148
+ dbSource .TestConnection = tcResponse
114
149
}
115
150
116
151
for _ , dbName := range dbList {
117
152
dbConn , listTC := checkConnection (ctx , conf , dbName )
118
153
if listTC != nil {
119
- return listTC , nil
154
+ dbSource .TestConnection = listTC
155
+ return dbSource , nil
120
156
}
121
157
122
158
listTC , err := checkContent (ctx , dbConn , dbName , imageContent )
123
159
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
125
165
}
126
166
127
167
if listTC != nil {
128
- return listTC , nil
168
+ dbSource .TestConnection = listTC
169
+ return dbSource , nil
129
170
}
130
171
}
131
172
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
153
174
}
154
175
155
176
func getDBList (ctx context.Context , conn * pgx.Conn , dbUsername string ) ([]string , error ) {
0 commit comments