Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复oracle相关规则的细化分类问题 #2844

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqle/driver/mysql/plocale/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ PrimaryKeyExistMessage = "Primary key already exists, cannot add it again."
PrimaryKeyNotExistMessage = "There is no primary key currently, cannot execute deletion."
RuleTypeDDLConvention = "DDL convention"
RuleTypeDMLConvention = "DML convention"
RuleTypeDQLConvention = "DQL convention"
RuleTypeDistributedConvention = "Distributed convention"
RuleTypeExecutePlan = "Execute plan"
RuleTypeGlobalConfig = "Global configuration"
Expand Down
1 change: 1 addition & 0 deletions sqle/driver/mysql/plocale/active.zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ PrimaryKeyExistMessage = "已经存在主键,不能再添加"
PrimaryKeyNotExistMessage = "当前没有主键,不能执行删除"
RuleTypeDDLConvention = "DDL规范"
RuleTypeDMLConvention = "DML规范"
RuleTypeDQLConvention = "DQL规范"
RuleTypeDistributedConvention = "分布式规范"
RuleTypeExecutePlan = "执行计划"
RuleTypeGlobalConfig = "全局配置"
Expand Down
1 change: 1 addition & 0 deletions sqle/driver/mysql/plocale/message_zh.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ var (
RuleTypeIndexingConvention = &i18n.Message{ID: "RuleTypeIndexingConvention", Other: "索引规范"}
RuleTypeDDLConvention = &i18n.Message{ID: "RuleTypeDDLConvention", Other: "DDL规范"}
RuleTypeDMLConvention = &i18n.Message{ID: "RuleTypeDMLConvention", Other: "DML规范"}
RuleTypeDQLConvention = &i18n.Message{ID: "RuleTypeDQLConvention", Other: "DQL规范"}
RuleTypeUsageSuggestion = &i18n.Message{ID: "RuleTypeUsageSuggestion", Other: "使用建议"}
RuleTypeIndexOptimization = &i18n.Message{ID: "RuleTypeIndexOptimization", Other: "索引优化"}
RuleTypeIndexInvalidation = &i18n.Message{ID: "RuleTypeIndexInvalidation", Other: "索引失效"}
Expand Down
31 changes: 26 additions & 5 deletions sqle/model/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,29 @@ func (s *Storage) CreateDefaultTemplateIfNotExist(projectId ProjectUID, rules ma
return nil
}

func mappingToNewCategory(ruleName string, oldCategory string) []string {
func mappingToNewCategory(ruleDesc string, oldCategory string) []string {
// 当旧规则是命名规范的映射关系
if oldCategory == plocale.RuleTypeNamingConvention.Other {
if strings.Contains(ruleName, "database") || strings.Contains(ruleName, "object") {
if strings.Contains(ruleDesc, plocale.RuleTagDatabase.Other) || strings.Contains(ruleDesc, "对象") {
return []string{plocale.RuleTagDatabase.ID}
} else if strings.Contains(ruleName, "index") || strings.Contains(ruleName, "pk") {
} else if strings.Contains(ruleDesc, plocale.RuleTagIndex.Other) || strings.Contains(ruleDesc, "主键") {
return []string{plocale.RuleTagIndex.ID}
} else if strings.Contains(ruleDesc, plocale.RuleTagTable.Other) {
return []string{plocale.RuleTagTable.ID}
} else if strings.Contains(ruleDesc, plocale.RuleTagView.Other) {
return []string{plocale.RuleTagView.ID}
} else if strings.Contains(ruleDesc, plocale.RuleTagColumn.Other) {
return []string{plocale.RuleTagColumn.ID}
} else if strings.Contains(ruleDesc, plocale.RuleTagProcedure.Other) {
return []string{plocale.RuleTagProcedure.ID}
} else if strings.Contains(ruleDesc, plocale.RuleTagFunction.Other) {
return []string{plocale.RuleTagFunction.ID}
} else if strings.Contains(ruleDesc, plocale.RuleTagTrigger.Other) {
return []string{plocale.RuleTagTrigger.ID}
} else if strings.Contains(ruleDesc, plocale.RuleTagEvent.Other) {
return []string{plocale.RuleTagEvent.ID}
} else if strings.Contains(ruleDesc, plocale.RuleTagUser.Other) {
return []string{plocale.RuleTagUser.ID}
} else {
return []string{
plocale.RuleTagDatabase.ID, plocale.RuleTagTablespace.ID, plocale.RuleTagTable.ID, plocale.RuleTagColumn.ID, plocale.RuleTagIndex.ID, plocale.RuleTagView.ID, plocale.RuleTagProcedure.ID, plocale.RuleTagFunction.ID, plocale.RuleTagTrigger.ID, plocale.RuleTagEvent.ID, plocale.RuleTagUser.ID}
Expand Down Expand Up @@ -599,6 +615,9 @@ var categoryMapping = map[string]map[string][]string{
plocale.RuleTypeDMLConvention.Other: {
plocale.RuleCategorySQL.ID: {plocale.RuleTagDML.ID},
},
plocale.RuleTypeDQLConvention.Other: {
plocale.RuleCategorySQL.ID: {plocale.RuleTagDML.ID},
},
plocale.RuleTypeUsageSuggestion.Other: {
plocale.RuleCategoryAuditPurpose.ID: {plocale.RuleTagMaintenance.ID},
},
Expand All @@ -611,7 +630,9 @@ var categoryMapping = map[string]map[string][]string{
}

func (s *Storage) UpdateRuleCategoryRels(rule *Rule) error {
oldCategory := rule.I18nRuleInfo.GetRuleInfoByLangTag(language.Chinese).Category
ruleInfo := rule.I18nRuleInfo.GetRuleInfoByLangTag(language.Chinese)
oldCategory := ruleInfo.Category
ruleDesc := ruleInfo.Desc
_, existed, err := s.FirstAuditRuleCategoryRelByRule(rule.Name, rule.DBType)
if err != nil {
return err
Expand All @@ -620,7 +641,7 @@ func (s *Storage) UpdateRuleCategoryRels(rule *Rule) error {
if existed {
return nil
}
tags := mappingToNewCategory(rule.Name, oldCategory)
tags := mappingToNewCategory(ruleDesc, oldCategory)
// 获取分类表中的分类信息
auditRuleCategories, err := s.GetAuditRuleCategoryByTagIn(tags)
if err != nil {
Expand Down
Loading