Skip to content

Dms/feat 2983#643

Merged
LordofAvernus merged 2 commits into
mainfrom
dms/feat-2983
Jun 22, 2026
Merged

Dms/feat 2983#643
LordofAvernus merged 2 commits into
mainfrom
dms/feat-2983

Conversation

@Seechi-Yolo

@Seechi-Yolo Seechi-Yolo commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

User description

关联的 issue

https://github.com/actiontech/sqle-ee/issues/2983

描述你的变更

为项目环境标签增加 color 字段的存储与 API 透传,并补齐数据源 tips 接口的环境标签信息,支撑前端带色环境标签展示。

主要改动

  • 环境标签 color 存储environment_tags 模型增加 color 字段,storage/biz/service 全链路读写
  • 环境标签 CRUD API:创建/更新/列表接口透传 color(沿用现有 environment_tag API)
  • ListDBServiceTips:返回 environment_tag(含 uid / name / color),供 DMS 选源下拉直接使用,避免前端二次请求合并
  • dms-common:同步 ListDBServiceTipItem 类型定义

兼容性

  • 存量环境标签 color 为空时保持中性展示,无需数据迁移脚本(依赖 auto_migrate 新增列)
  • 未打环境标签的数据源行为不变

依赖关系

  • 本 MR 应 先于 sqle、dms-ui 合并

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已记录完整日志方便进行诊断
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc


Description

  • 增加环境标签 color 字段存储

  • 扩展 API 接口透传 color 字段

  • 更新业务层及数据存储转换逻辑

  • 调整 swagger 模型定义支持 color


Diagram Walkthrough

flowchart LR
  A["API层: 接口参数更新"]
  B["Controller: 传递 color 参数"]
  C["Biz层: 新建及更新方法扩展"]
  D["Service层: 处理传递 color"]
  E["Storage层: 模型与转换更新"]
  A --> B
  B --> C
  C --> D
  D --> E
Loading

File Walkthrough

Relevant files
Enhancement
10 files
db_service.go
为 ListDBServiceTipItem 添加 EnvironmentTag 字段                           
+6/-5     
environment_tag.go
添加 color 字段到创建与更新请求                                                                           
+3/-1     
dms_controller.go
调用环境标签接口时附带 color 参数                                                                         
+2/-2     
environment_tag.go
方法签名更新,支持 color 参数传递                                                                         
+10/-8   
db_service.go
ListDBServiceTips 返回中增加 EnvironmentTag                                     
+6/-5     
environment_tag.go
更新服务层接口,加入 color 参数支持                                                                       
+7/-6     
convert.go
转换函数中处理 EnvironmentTag 的 color                                                     
+3/-2     
environment_tag.go
存储层转换及更新方法添加 color 字段                                                                       
+7/-2     
model.go
数据库模型中增加 color 字段定义                                                                           
+1/-0     
db_service.go
更新 swagger 模型,EnvironmentTag 支持 color                                       
+3/-2     

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

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

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
增加颜色格式验证

建议在创建环境标签时,对传入的 color 字段增加基本的格式校验,防止非法或过长的颜色值写入系统。可以在设置 Color 之前添加条件检查,确保其符合预期要求。

internal/dms/biz/environment_tag.go [53-58]

+    if color != "" && len(color) > 32 {
+    		return nil, fmt.Errorf("invalid color format: length must not exceed 32")
+    }
     return &EnvironmentTag{
     		UID:        uid,
     		Name:       tagName,
     		ProjectUID: projectUid,
-+		Color:      color,
-    	}, nil
+    		Color:      color,
+    }, nil
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly adds a basic validation check for the 'color' field, improving data integrity. However, it introduces extra logic that was not deemed mandatory in the diff, leading to a moderate impact.

Low
General
默认标签使用默认颜色

建议为默认环境标签提供明确的默认颜色值,而不是传入空字符串,这样可以避免后续因空颜色值处理不当引发潜在问题。可根据业务需求设置一个合理的默认颜色。

internal/dms/biz/environment_tag.go [70-76]

     for _, environmentTag := range defaultEnvironmentTags {
--		err = uc.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTag)
-+		err = uc.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTag, "")
- 		if err != nil {
- 			uc.log.Errorf("create environment tag failed: %v", err)
- 			return fmt.Errorf("create environment tag failed: %w", err)
- 		}
- 	}
+    		defaultColor := "default_color" // 根据实际需求设置默认颜色
+    		err = uc.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTag, defaultColor)
+    		if err != nil {
+    			uc.log.Errorf("create environment tag failed: %v", err)
+    			return fmt.Errorf("create environment tag failed: %w", err)
+    		}
+    }
Suggestion importance[1-10]: 4

__

Why: While providing an explicit default color could improve clarity, replacing the intentional use of an empty string may lead to unintended behavior if the system expects a blank value. The suggestion is acceptable but slightly intrusive given the existing design.

Low

@LordofAvernus LordofAvernus merged commit b98e673 into main Jun 22, 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.

2 participants