Alerting: Alert Rule migration (#33000)

* Not complete, put migration behind env flag for now:
UALERT_MIG=iDidBackup
* Important to backup, and not expect the same DB to keep working until the env trigger is removed.
* Alerting: Migrate dashboard alert permissions
* Do not use imported models
* Change folder titles

Co-authored-by: Sofia Papagiannaki <papagian@users.noreply.github.com>
This commit is contained in:
Kyle Brandt
2021-04-29 13:24:37 -04:00
committed by GitHub
parent cf958e0b4f
commit 6c8ef2a9c2
9 changed files with 1093 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
package ualert
// slurpDSIDs returns a map of [orgID, dataSourceId] -> [UID, Name].
func (m *migration) slurpDSIDs() (map[[2]int64][2]string, error) {
dsIDs := []struct {
OrgID int64 `xorm:"org_id"`
ID int64 `xorm:"id"`
UID string `xorm:"uid"`
Name string
}{}
err := m.sess.SQL(`SELECT org_id, id, uid, name FROM data_source`).Find(&dsIDs)
if err != nil {
return nil, err
}
idToUID := make(map[[2]int64][2]string, len(dsIDs))
for _, ds := range dsIDs {
idToUID[[2]int64{ds.OrgID, ds.ID}] = [2]string{ds.UID, ds.Name}
}
return idToUID, nil
}