From 0e4e8ac1dda729c962981c99ff537edda5b374b9 Mon Sep 17 00:00:00 2001 From: actiontech-zihan Date: Fri, 8 May 2026 11:13:55 +0000 Subject: [PATCH 1/3] feat(sql_workbench): add GoldenDB datasource type mapping and support check #814 - Add GoldenDB -> MYSQL mapping in convertDBType(), consistent with TDSQL For InnoDB approach (MySQL protocol compatible) - Add DBTypeGoldenDB to SupportDBType() so GoldenDB datasources enter ODC sync and EE provision flows - Add unit test cases for both functions covering GoldenDB --- internal/sql_workbench/service/sql_workbench_service.go | 4 +++- internal/sql_workbench/service/sql_workbench_service_test.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/sql_workbench/service/sql_workbench_service.go b/internal/sql_workbench/service/sql_workbench_service.go index 17823c3e2..3ed020c0d 100644 --- a/internal/sql_workbench/service/sql_workbench_service.go +++ b/internal/sql_workbench/service/sql_workbench_service.go @@ -930,13 +930,15 @@ func (sqlWorkbenchService *SqlWorkbenchService) convertDBType(dmsDBType string) return "DM" case "TiDB": return "TIDB" + case "GoldenDB": + return "MYSQL" default: return dmsDBType } } func (sqlWorkbenchService *SqlWorkbenchService) SupportDBType(dbType pkgConst.DBType) bool { - return dbType == pkgConst.DBTypeMySQL || dbType == pkgConst.DBTypeOracle || dbType == pkgConst.DBTypeOceanBaseMySQL || dbType == pkgConst.DBTypeDM || dbType == pkgConst.DBTypeTiDB + return dbType == pkgConst.DBTypeMySQL || dbType == pkgConst.DBTypeOracle || dbType == pkgConst.DBTypeOceanBaseMySQL || dbType == pkgConst.DBTypeDM || dbType == pkgConst.DBTypeTiDB || dbType == pkgConst.DBTypeGoldenDB } // buildDatabaseUser 当是ob-mysql时需要给账号管理的账号附加租户名集群名等字符: root@oms_mysql#oms_resource_4250 diff --git a/internal/sql_workbench/service/sql_workbench_service_test.go b/internal/sql_workbench/service/sql_workbench_service_test.go index e35809f11..42b78cb12 100644 --- a/internal/sql_workbench/service/sql_workbench_service_test.go +++ b/internal/sql_workbench/service/sql_workbench_service_test.go @@ -20,6 +20,7 @@ func Test_convertDBType(t *testing.T) { "OB Oracle": {input: "OceanBase For Oracle", expected: "OB_ORACLE"}, "OB MySQL": {input: "OceanBase For MySQL", expected: "OB_MYSQL"}, "TiDB": {input: "TiDB", expected: "TIDB"}, + "GoldenDB": {input: "GoldenDB", expected: "MYSQL"}, "Unknown passthrough": {input: "UnknownDB", expected: "UnknownDB"}, } for name, tc := range cases { @@ -43,6 +44,7 @@ func Test_SupportDBType(t *testing.T) { "Oracle supported": {input: pkgConst.DBTypeOracle, expected: true}, "OB MySQL supported": {input: pkgConst.DBTypeOceanBaseMySQL, expected: true}, "TiDB supported": {input: pkgConst.DBTypeTiDB, expected: true}, + "GoldenDB supported": {input: pkgConst.DBTypeGoldenDB, expected: true}, "PostgreSQL unsupported": {input: pkgConst.DBTypePostgreSQL, expected: false}, "SQL Server unsupported": {input: pkgConst.DBTypeSQLServer, expected: false}, } From f06611a88d82cc6e0aec69a576c04c1e94910180 Mon Sep 17 00:00:00 2001 From: actiontech-zihan Date: Fri, 8 May 2026 15:28:14 +0000 Subject: [PATCH 2/3] feat(sql_workbench): add DefaultSchema field to ODC datasource sync requests GoldenDB does not provide the information_schema database that ODC defaults to for MySQL-type connections, causing datasource status to be INACTIVE. Add DefaultSchema field to CreateDatasourceRequest, UpdateDatasourceRequest and datasourceBaseInfo so DMS can explicitly specify a default schema when syncing datasources to ODC. This change is paired with an ODC-side fix that stops hardcoding information_schema as the default schema for all MySQL-dialect types. Refs: actiontech/dms-ee#814 --- internal/sql_workbench/client/sql_workbench_client.go | 4 +++- internal/sql_workbench/service/sql_workbench_service.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/sql_workbench/client/sql_workbench_client.go b/internal/sql_workbench/client/sql_workbench_client.go index c4004af31..082e6b8be 100644 --- a/internal/sql_workbench/client/sql_workbench_client.go +++ b/internal/sql_workbench/client/sql_workbench_client.go @@ -978,9 +978,10 @@ type CreateDatasourceRequest struct { JdbcURLParameters map[string]interface{} `json:"jdbcUrlParameters"` Host string `json:"host"` Port string `json:"port"` + DefaultSchema *string `json:"defaultSchema,omitempty"` } -// UpdateDatasourceRequest 创建数据源请求结构 +// UpdateDatasourceRequest 更新数据源请求结构 type UpdateDatasourceRequest struct { Id int64 `json:"id"` CreatorID *int64 `json:"creatorId"` @@ -997,6 +998,7 @@ type UpdateDatasourceRequest struct { JdbcURLParameters *map[string]interface{} `json:"jdbcUrlParameters"` Host string `json:"host"` Port string `json:"port"` + DefaultSchema *string `json:"defaultSchema,omitempty"` } // DataSourceStatus 数据源状态结构 diff --git a/internal/sql_workbench/service/sql_workbench_service.go b/internal/sql_workbench/service/sql_workbench_service.go index 3ed020c0d..a819ae7f8 100644 --- a/internal/sql_workbench/service/sql_workbench_service.go +++ b/internal/sql_workbench/service/sql_workbench_service.go @@ -839,6 +839,7 @@ type datasourceBaseInfo struct { Port string ServiceName *string EnvironmentID int64 + DefaultSchema *string } // buildDatasourceBaseInfo 构建数据源基础信息 @@ -885,6 +886,7 @@ func (sqlWorkbenchService *SqlWorkbenchService) buildCreateDatasourceRequest(ctx ServiceName: baseInfo.ServiceName, SSLConfig: client.SSLConfig{Enabled: false}, EnvironmentID: baseInfo.EnvironmentID, + DefaultSchema: baseInfo.DefaultSchema, }, nil } @@ -905,6 +907,7 @@ func (sqlWorkbenchService *SqlWorkbenchService) buildUpdateDatasourceRequest(ctx ServiceName: baseInfo.ServiceName, SSLConfig: client.SSLConfig{Enabled: false}, EnvironmentID: baseInfo.EnvironmentID, + DefaultSchema: baseInfo.DefaultSchema, }, nil } From a7f7ec82b43b27f7db8d14194c10345327106de8 Mon Sep 17 00:00:00 2001 From: actiontech-zihan Date: Fri, 8 May 2026 17:13:21 +0000 Subject: [PATCH 3/3] fix: AuditMiddleware bypass SQL audit for DB types unsupported by SQLE SQLE lacks plugins for GoldenDB, TBase, DB2, Hive, GaussDB etc. The AuditMiddleware previously blocked all /streamExecute requests when audit was disabled (error: "please enable SQL audit first") and failed when audit was enabled (SQLE cannot audit unsupported types). This made SQL execution completely unusable for GoldenDB data sources. Add isSQLAuditSupportedDBType() to check whether the data source's db_type has a corresponding SQLE audit plugin. For unsupported types the middleware now passes the request through to ODC without auditing. Supported types (MySQL, Oracle, OceanBase MySQL, TiDB, PostgreSQL, SQL Server, DM) retain their existing audit behavior unchanged. Fixes actiontech/dms-ee#814 --- .../service/sql_workbench_service.go | 23 ++++++++++++++ .../service/sql_workbench_service_test.go | 30 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/internal/sql_workbench/service/sql_workbench_service.go b/internal/sql_workbench/service/sql_workbench_service.go index a819ae7f8..520b89add 100644 --- a/internal/sql_workbench/service/sql_workbench_service.go +++ b/internal/sql_workbench/service/sql_workbench_service.go @@ -1075,6 +1075,12 @@ func (sqlWorkbenchService *SqlWorkbenchService) AuditMiddleware() echo.Middlewar return errors.New(locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), locale.SqlWorkbenchAuditGetDBServiceErr)) } + // 对 SQLE 不支持审核的数据库类型(如 GoldenDB)直接放行,不做审核拦截 + if !sqlWorkbenchService.isSQLAuditSupportedDBType(dbService.DBType) { + sqlWorkbenchService.log.Infof("SQL audit not supported for db type %s (DBService: %s), bypassing audit", dbService.DBType, dmsDBServiceID) + return next(c) + } + // 检查是否启用 SQL 审核 if !sqlWorkbenchService.isEnableSQLAudit(dbService) { sqlWorkbenchService.log.Debugf("SQL audit is not enabled for DBService: %s", dmsDBServiceID) @@ -1230,6 +1236,23 @@ func (sqlWorkbenchService *SqlWorkbenchService) isEnableSQLAudit(dbService *biz. return dbService.SQLEConfig.AuditEnabled && dbService.SQLEConfig.SQLQueryConfig.AuditEnabled } +// isSQLAuditSupportedDBType 判断当前数据源类型是否被 SQLE 审核插件支持。 +// SQLE 仅对有对应审核插件的数据库类型提供审核能力;对于不在此列表中的类型 +// (如 GoldenDB、TBase、DB2 等),AuditMiddleware 应跳过审核直接放行。 +func (sqlWorkbenchService *SqlWorkbenchService) isSQLAuditSupportedDBType(dbType string) bool { + supportedTypes := map[string]struct{}{ + string(pkgConst.DBTypeMySQL): {}, + string(pkgConst.DBTypeOracle): {}, + string(pkgConst.DBTypeOceanBaseMySQL): {}, + string(pkgConst.DBTypeTiDB): {}, + string(pkgConst.DBTypePostgreSQL): {}, + string(pkgConst.DBTypeSQLServer): {}, + string(pkgConst.DBTypeDM): {}, + } + _, ok := supportedTypes[dbType] + return ok +} + // callSQLEAudit 调用 SQLE 直接审核接口 func (sqlWorkbenchService *SqlWorkbenchService) callSQLEAudit(ctx context.Context, sql string, dbService *biz.DBService) (*cloudbeaver.AuditSQLReply, error) { // 获取 SQLE 服务地址 diff --git a/internal/sql_workbench/service/sql_workbench_service_test.go b/internal/sql_workbench/service/sql_workbench_service_test.go index 42b78cb12..b14ba3064 100644 --- a/internal/sql_workbench/service/sql_workbench_service_test.go +++ b/internal/sql_workbench/service/sql_workbench_service_test.go @@ -33,6 +33,36 @@ func Test_convertDBType(t *testing.T) { } } +func Test_isSQLAuditSupportedDBType(t *testing.T) { + svc := &SqlWorkbenchService{} + cases := map[string]struct { + input string + expected bool + }{ + "MySQL supported": {input: string(pkgConst.DBTypeMySQL), expected: true}, + "Oracle supported": {input: string(pkgConst.DBTypeOracle), expected: true}, + "OB MySQL supported": {input: string(pkgConst.DBTypeOceanBaseMySQL), expected: true}, + "TiDB supported": {input: string(pkgConst.DBTypeTiDB), expected: true}, + "PostgreSQL supported": {input: string(pkgConst.DBTypePostgreSQL), expected: true}, + "SQL Server supported": {input: string(pkgConst.DBTypeSQLServer), expected: true}, + "DM supported": {input: string(pkgConst.DBTypeDM), expected: true}, + "GoldenDB not supported": {input: string(pkgConst.DBTypeGoldenDB), expected: false}, + "TBase not supported": {input: string(pkgConst.DBTypeTBase), expected: false}, + "DB2 not supported": {input: string(pkgConst.DBTypeDB2), expected: false}, + "Hive not supported": {input: string(pkgConst.DBTypeHive), expected: false}, + "GaussDB not supported": {input: string(pkgConst.DBTypeGaussDB), expected: false}, + "Unknown not supported": {input: "UnknownDB", expected: false}, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + got := svc.isSQLAuditSupportedDBType(tc.input) + if got != tc.expected { + t.Errorf("isSQLAuditSupportedDBType(%q) = %v, want %v", tc.input, got, tc.expected) + } + }) + } +} + func Test_SupportDBType(t *testing.T) { svc := &SqlWorkbenchService{} cases := map[string]struct {