diff --git a/pkg/services/sqlstore/migrations/ualert/alert_rule.go b/pkg/services/sqlstore/migrations/ualert/alert_rule.go index df500ce83ee..faad6438add 100644 --- a/pkg/services/sqlstore/migrations/ualert/alert_rule.go +++ b/pkg/services/sqlstore/migrations/ualert/alert_rule.go @@ -72,18 +72,25 @@ func (a *alertRule) makeVersion() *alertRuleVersion { } } -func getMigrationInfo(da dashAlert) string { +func addMigrationInfo(da *dashAlert) map[string]string { + annotations := da.ParsedSettings.AlertRuleTags + if annotations == nil { + annotations = make(map[string]string, 3) + } + + annotations["__dashboardUid__"] = da.DashboardUID + annotations["__panelId__"] = fmt.Sprintf("%v", da.PanelId) + annotations["__alertId__"] = fmt.Sprintf("%v", da.Id) + + return annotations +} + +func getMigrationString(da dashAlert) string { return fmt.Sprintf(`{"dashboardUid": "%v", "panelId": %v, "alertId": %v}`, da.DashboardUID, da.PanelId, da.Id) } func (m *migration) makeAlertRule(cond condition, da dashAlert, folderUID string) (*alertRule, error) { - migAnnotation := getMigrationInfo(da) - - annotations := da.ParsedSettings.AlertRuleTags - if annotations == nil { - annotations = make(map[string]string, 1) - } - annotations["__migration__info__"] = migAnnotation + annotations := addMigrationInfo(&da) ar := &alertRule{ OrgId: da.OrgId, diff --git a/pkg/services/sqlstore/migrations/ualert/ualert.go b/pkg/services/sqlstore/migrations/ualert/ualert.go index 3ffb5dddd60..cb267c4f773 100644 --- a/pkg/services/sqlstore/migrations/ualert/ualert.go +++ b/pkg/services/sqlstore/migrations/ualert/ualert.go @@ -113,7 +113,7 @@ func (m *migration) Exec(sess *xorm.Session, mg *migrator.Migrator) error { switch { case dash.HasAcl: // create folder and assign the permissions of the dashboard (included default and inherited) - ptr, err := m.createFolder(dash.OrgId, fmt.Sprintf(DASHBOARD_FOLDER, getMigrationInfo(da))) + ptr, err := m.createFolder(dash.OrgId, fmt.Sprintf(DASHBOARD_FOLDER, getMigrationString(da))) if err != nil { return MigrationError{ Err: fmt.Errorf("failed to create folder: %w", err),