mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Update migration to migrate only alerts that belong to existing org\dashboard (#49192)
* Update migration to migrate only alerts that belong to existing org\dashboard
This commit is contained in:
parent
859cc92da7
commit
d87fdc1037
@ -54,6 +54,7 @@ Scopes must have an order to ensure consistency and ease of search, this helps u
|
||||
- [FEATURE] Indicate whether routes are provisioned when GETting Alertmanager configuration #47857
|
||||
- [FEATURE] Indicate whether contact point is provisioned when GETting Alertmanager configuration #48323
|
||||
- [FEATURE] Indicate whether alert rule is provisioned when GETting the rule #48458
|
||||
- [BUGFIX] Migration: ignore alerts that do not belong to any existing organization\dashboard #49192
|
||||
|
||||
## 8.5.3
|
||||
|
||||
|
@ -36,10 +36,12 @@ SELECT id,
|
||||
settings
|
||||
FROM
|
||||
alert
|
||||
WHERE org_id IN (SELECT id from org)
|
||||
AND dashboard_id IN (SELECT id from dashboard)
|
||||
`
|
||||
|
||||
// slurpDashAlerts loads all alerts from the alert database table into the
|
||||
// the dashAlert type.
|
||||
// the dashAlert type. If there are alerts that belong to either organization or dashboard that does not exist, those alerts will not be returned/
|
||||
// Additionally it unmarshals the json settings for the alert into the
|
||||
// ParsedSettings property of the dash alert.
|
||||
func (m *migration) slurpDashAlerts() ([]dashAlert, error) {
|
||||
|
@ -568,9 +568,22 @@ func createDatasource(t *testing.T, id int64, orgId int64, uid string) *models.D
|
||||
}
|
||||
}
|
||||
|
||||
func createOrg(t *testing.T, id int64) *models.Org {
|
||||
t.Helper()
|
||||
return &models.Org{
|
||||
Id: id,
|
||||
Version: 1,
|
||||
Name: fmt.Sprintf("org_%d", id),
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
// teardown cleans the input tables between test cases.
|
||||
func teardown(t *testing.T, x *xorm.Engine) {
|
||||
_, err := x.Exec("DELETE from alert")
|
||||
_, err := x.Exec("DELETE from org")
|
||||
require.NoError(t, err)
|
||||
_, err = x.Exec("DELETE from alert")
|
||||
require.NoError(t, err)
|
||||
_, err = x.Exec("DELETE from alert_notification")
|
||||
require.NoError(t, err)
|
||||
@ -584,6 +597,11 @@ func teardown(t *testing.T, x *xorm.Engine) {
|
||||
func setupLegacyAlertsTables(t *testing.T, x *xorm.Engine, legacyChannels []*models.AlertNotification, alerts []*models.Alert) {
|
||||
t.Helper()
|
||||
|
||||
orgs := []models.Org{
|
||||
*createOrg(t, 1),
|
||||
*createOrg(t, 2),
|
||||
}
|
||||
|
||||
// Setup dashboards.
|
||||
dashboards := []models.Dashboard{
|
||||
*createDashboard(t, 1, 1, "dash1-1"),
|
||||
@ -601,6 +619,10 @@ func setupLegacyAlertsTables(t *testing.T, x *xorm.Engine, legacyChannels []*mod
|
||||
*createDatasource(t, 3, 2, "ds3-2"),
|
||||
*createDatasource(t, 4, 2, "ds4-2"),
|
||||
}
|
||||
|
||||
_, errOrgs := x.Insert(orgs)
|
||||
require.NoError(t, errOrgs)
|
||||
|
||||
_, errDataSourcess := x.Insert(dataSources)
|
||||
require.NoError(t, errDataSourcess)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user