Skip to content

Commit f8fb414

Browse files
authored
Merge pull request #631 from actiontech/dev-865
feat(sql_workbench): support GaussDB / PostgreSQL whitelist + fix /odc_query proxy fallback
2 parents f26bb6f + 8ee5413 commit f8fb414

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

internal/apiserver/service/router.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ func (s *APIServer) installMiddleware() error {
451451

452452
s.echo.Use(middleware.StaticWithConfig(middleware.StaticConfig{
453453
Skipper: middleware.Skipper(func(c echo.Context) bool {
454+
// 必须先跳过 /odc_query,避免 DMS 自身的 static fallback 把
455+
// `/odc_query/`、`/odc_query/index.html` 等子路径返回为 DMS index.html,
456+
// 导致 ODC SQL 工作台跳转被截获。无尾斜杠的 /odc_query 由 Group route
457+
// 直接走 ProxyConfig 代理到 ODC 8989,本 Skipper 不影响。
458+
if strings.HasPrefix(c.Request().URL.Path, s.SqlWorkbenchController.SqlWorkbenchService.GetRootUri()) {
459+
return true
460+
}
454461
if strings.HasPrefix(c.Request().URL.Path, s.SqlWorkbenchController.CloudbeaverService.CloudbeaverUsecase.GetRootUri()) {
455462
return true
456463
}

internal/sql_workbench/service/sql_workbench_service.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,13 +945,15 @@ func (sqlWorkbenchService *SqlWorkbenchService) buildUpdateDatasourceRequest(ctx
945945
// convertDBType 转换数据库类型
946946
func (sqlWorkbenchService *SqlWorkbenchService) convertDBType(dmsDBType string) string {
947947
// 这里需要根据实际的数据库类型映射关系进行转换
948-
// ODC目前支持的数据源有: OB_MYSQL, OB_ORACLE, ORACLE, MYSQL, ODP_SHARDING_OB_MYSQL, DORIS, POSTGRESQL
948+
// ODC目前支持的数据源有: OB_MYSQL, OB_ORACLE, ORACLE, MYSQL, ODP_SHARDING_OB_MYSQL, DORIS, POSTGRESQL, GAUSSDB
949949
// 其余调用创建数据源接口会直接失败
950950
switch dmsDBType {
951951
case "MySQL":
952952
return "MYSQL"
953953
case "PostgreSQL":
954954
return "POSTGRESQL"
955+
case "GaussDB":
956+
return "GAUSSDB"
955957
case "Oracle":
956958
return "ORACLE"
957959
case "SQL Server":
@@ -985,7 +987,9 @@ func (sqlWorkbenchService *SqlWorkbenchService) SupportDBType(dbType pkgConst.DB
985987
dbType == pkgConst.DBTypeTiDB ||
986988
dbType == pkgConst.DBTypeTDSQLForInnoDB ||
987989
dbType == pkgConst.DBTypeGoldenDB ||
988-
dbType == pkgConst.DBTypePolarDBForMySQL
990+
dbType == pkgConst.DBTypePolarDBForMySQL ||
991+
dbType == pkgConst.DBTypeGaussDB ||
992+
dbType == pkgConst.DBTypePostgreSQL
989993
}
990994

991995
func buildMongoDatasourceOptions(dbService *biz.DBService) (*string, interface{}, map[string]interface{}) {

internal/sql_workbench/service/sql_workbench_service_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func Test_convertDBType(t *testing.T) {
2525
"TDSQL For InnoDB": {input: "TDSQL For InnoDB", expected: "MYSQL"},
2626
"GoldenDB": {input: "GoldenDB", expected: "MYSQL"},
2727
"PolarDB For MySQL": {input: "PolarDB For MySQL", expected: "MYSQL"},
28+
"GaussDB": {input: "GaussDB", expected: "GAUSSDB"},
2829
"MongoDB": {input: "MongoDB", expected: "MONGODB"},
2930
"Unknown passthrough": {input: "UnknownDB", expected: "UnknownDB"},
3031
}
@@ -52,9 +53,11 @@ func Test_SupportDBType(t *testing.T) {
5253
"TDSQL supported": {input: pkgConst.DBTypeTDSQLForInnoDB, expected: true},
5354
"GoldenDB supported": {input: pkgConst.DBTypeGoldenDB, expected: true},
5455
"MongoDB unsupported": {input: pkgConst.DBTypeMongoDB, expected: false},
55-
"PostgreSQL unsupported": {input: pkgConst.DBTypePostgreSQL, expected: false},
56+
"PostgreSQL supported": {input: pkgConst.DBTypePostgreSQL, expected: true},
5657
"SQL Server unsupported": {input: pkgConst.DBTypeSQLServer, expected: false},
5758
"PolarDB For MySQL supported": {input: pkgConst.DBTypePolarDBForMySQL, expected: true},
59+
"GaussDB supported": {input: pkgConst.DBTypeGaussDB, expected: true},
60+
"GaussDBForMySQL unsupported": {input: pkgConst.DBTypeGaussDBForMySQL, expected: false},
5861
}
5962
for name, tc := range cases {
6063
t.Run(name, func(t *testing.T) {
@@ -66,6 +69,18 @@ func Test_SupportDBType(t *testing.T) {
6669
}
6770
}
6871

72+
func Test_SupportDBType_GaussDB_PG_family_consistency(t *testing.T) {
73+
svc := &SqlWorkbenchService{}
74+
// CR-13: design §1.2 decision-3 locks PG family (PostgreSQL + GaussDB)
75+
// must be whitelisted together; SQL workbench routing assumes the pair.
76+
if got := svc.SupportDBType(pkgConst.DBTypePostgreSQL); !got {
77+
t.Errorf("PostgreSQL must be supported (CR-13 / EARS-1.2)")
78+
}
79+
if got := svc.SupportDBType(pkgConst.DBTypeGaussDB); !got {
80+
t.Errorf("GaussDB must be supported (EARS-1.2 / decision-3)")
81+
}
82+
}
83+
6984
func Test_buildMongoDatasourceOptions(t *testing.T) {
7085
defaultDB := "appdb"
7186
defaultSchema, propertiesValue, jdbcParams := buildMongoDatasourceOptions(&biz.DBService{

0 commit comments

Comments
 (0)