Alerting: Fix migration to create rules with group index 1 (#56511)

This commit is contained in:
Yuriy Tseretyan 2022-10-07 17:20:01 -04:00 committed by GitHub
parent e2f1201382
commit 3487e68d15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -122,6 +122,7 @@ func (m *migration) makeAlertRule(cond condition, da dashAlert, folderUID string
Updated: time.Now().UTC(),
Annotations: annotations,
Labels: lbls,
RuleGroupIndex: 1,
}
ar.NoDataState, err = transNoData(da.ParsedSettings.NoDataState)

View File

@ -839,7 +839,7 @@ func (c updateRulesOrderInGroup) Exec(sess *xorm.Session, migrator *migrator.Mig
}
updated := time.Now()
versions := make([]*alertRuleVersion, 0, len(toUpdate))
versions := make([]interface{}, 0, len(toUpdate))
for _, rule := range toUpdate {
rule.Updated = updated
@ -855,8 +855,7 @@ func (c updateRulesOrderInGroup) Exec(sess *xorm.Session, migrator *migrator.Mig
migrator.Logger.Debug("updated group index for alert rule", "rule_uid", rule.UID)
versions = append(versions, version)
}
_, err := sess.Insert(&versions)
_, err := sess.Insert(versions...)
if err != nil {
migrator.Logger.Error("failed to insert changes to alert_rule_version", "err", err)
return fmt.Errorf("unable to update alert rules with group index: %w", err)