diff --git a/sqle/model/utils.go b/sqle/model/utils.go index 6e0a2598f5..c504acd881 100644 --- a/sqle/model/utils.go +++ b/sqle/model/utils.go @@ -159,14 +159,21 @@ func (s *Storage) CreateRulesIfNotExist(rules map[string][]*driver.Rule) error { } // rule will be created or update if: // 1. rule not exist; - // 2. rule no params in db, and has params in code. - existedRuleHasParams := existedRule.Params != nil && len(existedRule.Params.Params) > 0 - ruleHasParams := len(rule.Params) > 0 - if !exist || (!existedRuleHasParams && ruleHasParams) { - err = s.Save(GenerateRuleByDriverRule(rule, dbType)) + if !exist { + err := s.Save(GenerateRuleByDriverRule(rule, dbType)) if err != nil { return err } + } else { + // 2. rule no params in db, and has params in code. + existedRuleHasParams := existedRule.Params != nil && len(existedRule.Params.Params) > 0 + ruleHasParams := len(rule.Params) > 0 + if !exist || (!existedRuleHasParams && ruleHasParams) { + err := s.Save(GenerateRuleByDriverRule(rule, dbType)) + if err != nil { + return err + } + } } } }