Skip to content

Commit

Permalink
Merge pull request #2844 from actiontech/fix_new_category_opt
Browse files Browse the repository at this point in the history
fix: 修复oracle相关规则的细化分类问题
  • Loading branch information
ColdWaterLW authored Dec 27, 2024
2 parents 18d0573 + 3e658c9 commit a51f0a2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
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

0 comments on commit a51f0a2

Please sign in to comment.