Skip to content

Commit 92f3066

Browse files
committed
Merge branch 'source-properties' into 'master'
fix: return the source database version and tuning params in any case See merge request postgres-ai/database-lab!796
2 parents edb571d + a2ea4fd commit 92f3066

File tree

2 files changed

+59
-30
lines changed
  • engine
    • internal/retrieval/engine/postgres/tools/db
    • pkg/models

2 files changed

+59
-30
lines changed

Diff for: engine/internal/retrieval/engine/postgres/tools/db/pg.go

+48-27
Original file line numberDiff line numberDiff line change
@@ -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

155176
func getDBList(ctx context.Context, conn *pgx.Conn, dbUsername string) ([]string, error) {

Diff for: engine/pkg/models/admin.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const (
1919
// TCResultConnectionError defines a connection error of the test connection request.
2020
TCResultConnectionError = "connection_error"
2121

22+
// TCResultQueryError defines a query error of the test connection request.
23+
TCResultQueryError = "query_error"
24+
2225
// TCResultUnexploredImage defines the notice about unexplored Docker image yet.
2326
TCResultUnexploredImage = "unexplored_image"
2427

@@ -37,9 +40,14 @@ const (
3740

3841
// TestConnection represents the response of the test connection request.
3942
type TestConnection struct {
40-
Status string `json:"status"`
41-
Result string `json:"result"`
42-
Message string `json:"message"`
43+
Status string `json:"status"`
44+
Result string `json:"result"`
45+
Message string `json:"message"`
46+
}
47+
48+
// DBSource represents the response of the database source checks.
49+
type DBSource struct {
50+
*TestConnection
4351
DBVersion int `json:"dbVersion,omitempty"`
4452
TuningParams map[string]string `json:"tuningParams"`
4553
}

0 commit comments

Comments
 (0)