Skip to content

feat(sql_workbench): support DB2 in DMS->ODC bridge (Fixes actiontech/dms-ee#839)#636

Merged
Seechi-Yolo merged 1 commit into
mainfrom
feat-839
Jun 1, 2026
Merged

feat(sql_workbench): support DB2 in DMS->ODC bridge (Fixes actiontech/dms-ee#839)#636
Seechi-Yolo merged 1 commit into
mainfrom
feat-839

Conversation

@actiontech-bot
Copy link
Copy Markdown
Member

@actiontech-bot actiontech-bot commented Jun 1, 2026

User description

Summary

Wire DB2 through the DMS→ODC SQL workbench bridge so the dms front-end can open the ODC console against a DB2 datasource registered in DMS.

  • SqlWorkbenchService.convertDBType: add explicit "DB2" -> "DB2" mapping aligned with ODC ConnectType.DB2 literal (compat-RISK-2 align).
  • SqlWorkbenchService.buildDatasourceBaseInfo: extract pure fillDatasourceBaseInfo helper (no IO) to make DBType-branch logic unit-testable; add DB2 branch passing AdditionalParams.database_namebaseInfo.DefaultSchema; fail-fast with error containing database_name when missing (compat-RISK-5 decision A).
  • Tests:
    • Test_convertDBType: add DB2 row + regression coverage for existing types.
    • Test_buildDatasourceBaseInfo_DB2: 4 sub-cases (DB2 happy path / DB2 missing database_name negative / MySQL regression / Oracle regression).
    • Test_SupportDBType: add DB2 unsupported reverse-locking case per compat-RISK-1 decision A — DB2 stays out of SupportDBType (sql_workbench EE side) until EE follow-up wires audit / approval.
  • chore: align sql_workbench_service_test.go reference to the renamed constant pkgConst.DBTypePolarDBForMySQL (typo in PR #816 baseline that was blocking the test package from building).

Design / compat doc lives in EE workspace (actiontech/dms-ee#839 description, docs/spec/design.md §4, docs/spec/compat_risks.md RISK-1 / RISK-2 / RISK-5).

Test plan

  • go vet ./internal/sql_workbench/... PASS (golang:1.24.1)
  • go test ./internal/sql_workbench/service/...Test_convertDBType 12 sub-cases / Test_SupportDBType 11 sub-cases / Test_buildDatasourceBaseInfo_DB2 4 sub-cases — all PASS
  • End-to-end manual: DMS → 工作台 → DB2 数据源 → ODC console 跳转返回 200,ODC 侧 ConnectType=DB2 + defaultSchema=<database_name>

Fixes actiontech/dms-ee#839
Related: actiontech/odc PR #24, actiontech/odc-client PR #34


Description

  • 添加填充数据源信息的辅助函数,支持无 IO 分支逻辑

  • 增加 DB2 特殊处理,校验 AdditionalParams 中的 database_name

  • 在 convertDBType 中新增 DB2 映射

  • 增加单元测试覆盖 DB2 正例与负例


Diagram Walkthrough

flowchart LR
  A["\"新增辅助函数 fillDatasourceBaseInfo\""] --> B["\"增加 DB2 特殊逻辑处理\""]
  B --> C["\"在 convertDBType 中添加 DB2 映射\""]
  C --> D["\"扩展测试覆盖多场景\""]
Loading

File Walkthrough

Relevant files
Enhancement
sql_workbench_service.go
支持 DB2 数据源逻辑添加与重构                                                                               

internal/sql_workbench/service/sql_workbench_service.go

  • 新增辅助函数 fillDatasourceBaseInfo
  • 在 buildDatasourceBaseInfo 中调用辅助函数
  • 增加 DB2 分支处理及参数校验
  • 更新 convertDBType 中的 DB2 映射逻辑
+20/-1   
Tests
sql_workbench_service_test.go
扩展 DB2 测试用例与回归验证                                                                                 

internal/sql_workbench/service/sql_workbench_service_test.go

  • 新增 Test_buildDatasourceBaseInfo_DB2 单元测试
  • 增加 DB2 正例与缺失参数负例测试
  • 扩展 Test_convertDBType 与 Test_SupportDBType 的覆盖范围
+105/-0 

…buildDatasourceBaseInfo)

- convertDBType: add explicit case "DB2" -> "DB2" (D-01, compat-RISK-2 align with ODC ConnectType.DB2 literal)
- buildDatasourceBaseInfo: add DB2 branch passing AdditionalParams.database_name -> baseInfo.DefaultSchema, fail-fast with error containing "database_name" when missing (D-02, compat-RISK-5 decision A)
- Test_convertDBType: add "DB2": {input: "DB2", expected: "DB2"} (D-03)
- Test_buildDatasourceBaseInfo_DB2: new map-case test with 4 groups - DB2 happy path / DB2 missing database_name negative / MySQL regression / Oracle regression (D-04)
- Test_SupportDBType: add "DB2 unsupported" reverse-locking case per compat-RISK-1 decision A (D-S1)
- SupportDBType / sql_workbench_service_ee.go intentionally not changed per design §4.2 + compat-RISK-1 decision A

Refs: actiontech/dms-ee#839
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
检查 nil 指针

建议在使用 dbService.AdditionalParams 前先检查其是否为 nil,以防止出现空指针 dereference 导致 panic。添加一个 nil
检查可以提升代码的健壮性,确保在 AdditionalParams 为空时能返回明确的错误信息。

internal/sql_workbench/service/sql_workbench_service.go [902-909]

 if dbService.DBType == "DB2" {
+    if dbService.AdditionalParams == nil {
+        return nil, fmt.Errorf("DB2 数据源 %s 的 AdditionalParams 为 nil", dbService.Name)
+    }
 	databaseNameParam := dbService.AdditionalParams.GetParam("database_name")
 	if databaseNameParam == nil || databaseNameParam.Value == "" {
 		return nil, fmt.Errorf("DB2 数据源 %s 缺少 AdditionalParam database_name,请在数据源 AdditionalParams 中补充", dbService.Name)
 	}
 	databaseName := databaseNameParam.Value
 	baseInfo.DefaultSchema = &databaseName
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion adds a nil check for dbService.AdditionalParams in the DB2 block, which improves error handling and avoids potential panic. This change enhances the robustness of the fillDatasourceBaseInfo function.

Medium
General
增加nil测试用例

建议在单元测试中增加一个测试用例,验证当 dbService.AdditionalParams 为 nil 时,函数能够正确返回错误,而不是触发
panic。这有助于覆盖更多异常状况,提高代码稳定性和测试覆盖率。

internal/sql_workbench/service/sql_workbench_service_test.go [156-167]

 cases := map[string]struct {
 	dbService            *biz.DBService
 	expectErr            bool
 	expectErrSubstr      string
 	expectDefaultSchema  *string
 	expectServiceName    *string
 }{
 	"DB2 happy path": { ... },
 	"DB2 missing database_name": { ... },
+	"DB2 nil AdditionalParams": {
+		dbService: &biz.DBService{
+			Name:             "db2-3",
+			DBType:           "DB2",
+			AdditionalParams: nil,
+		},
+		expectErr:       true,
+		expectErrSubstr: "AdditionalParams 为 nil",
+	},
 	"MySQL regression": { ... },
 	"Oracle regression": { ... },
 }
Suggestion importance[1-10]: 6

__

Why: The suggestion proposes adding a new test case to cover the scenario where AdditionalParams is nil, increasing test coverage and stability. It is a valuable but moderate improvement for unit tests.

Low

@Seechi-Yolo Seechi-Yolo merged commit 5783501 into main Jun 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants