Skip to content

Commit

Permalink
Alerting: Fix migration to create rules with group index 1 (#56511) (#…
Browse files Browse the repository at this point in the history
…56584)

(cherry picked from commit 3487e68)

Co-authored-by: Yuriy Tseretyan <yuriy.tseretyan@grafana.com>
  • Loading branch information
grafanabot and yuri-tceretian committed Oct 7, 2022
1 parent 77046b3 commit 1024334
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/services/sqlstore/migrations/ualert/alert_rule.go
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions pkg/services/sqlstore/migrations/ualert/ualert.go
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 1024334

Please sign in to comment.