Skip to content

Commit 77260e8

Browse files
committed
feat(sql_workbench): support GaussDB / PostgreSQL in SQL workbench whitelist
- SupportDBType: add DBTypeGaussDB + DBTypePostgreSQL to whitelist (EARS-1.2 / decision-3 positive coverage for KF-2) - convertDBType: add "GaussDB" -> "GAUSSDB" mapping immediately after the existing "PostgreSQL" -> "POSTGRESQL" mapping (EARS-1.3 / CR-12 case-sensitivity normalization) - unit tests: - Test_convertDBType: new "GaussDB" case (13 total); existing "PostgreSQL" / "Unknown passthrough" regressed unchanged - Test_SupportDBType: flip "PostgreSQL" expected from false to true (decision-3 lock); new "GaussDB supported" + "GaussDBForMySQL unsupported" cases; existing SQL Server negative regression kept - Test_SupportDBType_GaussDB_PG_family_consistency: hard assertion PG family (PostgreSQL + GaussDB) whitelist coupling Related: actiontech/dms-ee#865
1 parent 0c651d4 commit 77260e8

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

internal/sql_workbench/service/sql_workbench_service.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,13 +925,15 @@ func (sqlWorkbenchService *SqlWorkbenchService) buildUpdateDatasourceRequest(ctx
925925
// convertDBType 转换数据库类型
926926
func (sqlWorkbenchService *SqlWorkbenchService) convertDBType(dmsDBType string) string {
927927
// 这里需要根据实际的数据库类型映射关系进行转换
928-
// ODC目前支持的数据源有: OB_MYSQL, OB_ORACLE, ORACLE, MYSQL, ODP_SHARDING_OB_MYSQL, DORIS, POSTGRESQL
928+
// ODC目前支持的数据源有: OB_MYSQL, OB_ORACLE, ORACLE, MYSQL, ODP_SHARDING_OB_MYSQL, DORIS, POSTGRESQL, GAUSSDB
929929
// 其余调用创建数据源接口会直接失败
930930
switch dmsDBType {
931931
case "MySQL":
932932
return "MYSQL"
933933
case "PostgreSQL":
934934
return "POSTGRESQL"
935+
case "GaussDB":
936+
return "GAUSSDB"
935937
case "Oracle":
936938
return "ORACLE"
937939
case "SQL Server":
@@ -963,7 +965,9 @@ func (sqlWorkbenchService *SqlWorkbenchService) SupportDBType(dbType pkgConst.DB
963965
dbType == pkgConst.DBTypeTiDB ||
964966
dbType == pkgConst.DBTypeTDSQLForInnoDB ||
965967
dbType == pkgConst.DBTypeGoldenDB ||
966-
dbType == pkgConst.DBTypePolarDBForMySQL
968+
dbType == pkgConst.DBTypePolarDBForMySQL ||
969+
dbType == pkgConst.DBTypeGaussDB ||
970+
dbType == pkgConst.DBTypePostgreSQL
967971
}
968972

969973
// buildDatabaseUser 当是ob-mysql时需要给账号管理的账号附加租户名集群名等字符: root@oms_mysql#oms_resource_4250

internal/sql_workbench/service/sql_workbench_service_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func Test_convertDBType(t *testing.T) {
2323
"TDSQL For InnoDB": {input: "TDSQL For InnoDB", expected: "MYSQL"},
2424
"GoldenDB": {input: "GoldenDB", expected: "MYSQL"},
2525
"PolarDB For MySQL": {input: "PolarDB For MySQL", expected: "MYSQL"},
26+
"GaussDB": {input: "GaussDB", expected: "GAUSSDB"},
2627
"Unknown passthrough": {input: "UnknownDB", expected: "UnknownDB"},
2728
}
2829
for name, tc := range cases {
@@ -48,9 +49,11 @@ func Test_SupportDBType(t *testing.T) {
4849
"TiDB supported": {input: pkgConst.DBTypeTiDB, expected: true},
4950
"TDSQL supported": {input: pkgConst.DBTypeTDSQLForInnoDB, expected: true},
5051
"GoldenDB supported": {input: pkgConst.DBTypeGoldenDB, expected: true},
51-
"PostgreSQL unsupported": {input: pkgConst.DBTypePostgreSQL, expected: false},
52+
"PostgreSQL supported": {input: pkgConst.DBTypePostgreSQL, expected: true},
5253
"SQL Server unsupported": {input: pkgConst.DBTypeSQLServer, expected: false},
5354
"PolarDB For MySQL supported": {input: pkgConst.DBTypePolarDBForMySQL, expected: true},
55+
"GaussDB supported": {input: pkgConst.DBTypeGaussDB, expected: true},
56+
"GaussDBForMySQL unsupported": {input: pkgConst.DBTypeGaussDBForMySQL, expected: false},
5457
}
5558
for name, tc := range cases {
5659
t.Run(name, func(t *testing.T) {
@@ -61,3 +64,15 @@ func Test_SupportDBType(t *testing.T) {
6164
})
6265
}
6366
}
67+
68+
func Test_SupportDBType_GaussDB_PG_family_consistency(t *testing.T) {
69+
svc := &SqlWorkbenchService{}
70+
// CR-13: design §1.2 decision-3 locks PG family (PostgreSQL + GaussDB)
71+
// must be whitelisted together; SQL workbench routing assumes the pair.
72+
if got := svc.SupportDBType(pkgConst.DBTypePostgreSQL); !got {
73+
t.Errorf("PostgreSQL must be supported (CR-13 / EARS-1.2)")
74+
}
75+
if got := svc.SupportDBType(pkgConst.DBTypeGaussDB); !got {
76+
t.Errorf("GaussDB must be supported (EARS-1.2 / decision-3)")
77+
}
78+
}

0 commit comments

Comments
 (0)