mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): delete alerts when dashboard gets deleted
This commit is contained in:
@@ -128,13 +128,39 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
/*
|
||||
Convey("When dashboard is removed", func() {
|
||||
items := []m.Alert{
|
||||
{
|
||||
PanelId: 1,
|
||||
DashboardId: testDash.Id,
|
||||
Query: "Query",
|
||||
QueryRefId: "A",
|
||||
WarnLevel: "> 30",
|
||||
CritLevel: "> 50",
|
||||
Interval: "10",
|
||||
Title: "Alerting title",
|
||||
Description: "Alerting description",
|
||||
QueryRange: "5m",
|
||||
Aggregator: "avg",
|
||||
},
|
||||
}
|
||||
|
||||
cmd := m.SaveAlertsCommand{
|
||||
Alerts: &items,
|
||||
DashboardId: testDash.Id,
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
}
|
||||
|
||||
SaveAlerts(&cmd)
|
||||
|
||||
DeleteDashboard(&m.DeleteDashboardCommand{
|
||||
OrgId: 1,
|
||||
Slug: testDash.Slug,
|
||||
})
|
||||
|
||||
/* Uncomment this once we know why inTransaction2 is failing in unit tests
|
||||
|
||||
Convey("Alerts should be removed", func() {
|
||||
alerts, err2 := GetAlertsByDashboardId(testDash.Id)
|
||||
|
||||
@@ -142,7 +168,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
So(err2, ShouldBeNil)
|
||||
So(len(alerts), ShouldEqual, 0)
|
||||
})
|
||||
})
|
||||
*/
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -227,6 +227,7 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
|
||||
"DELETE FROM dashboard_tag WHERE dashboard_id = ? ",
|
||||
"DELETE FROM star WHERE dashboard_id = ? ",
|
||||
"DELETE FROM dashboard WHERE id = ?",
|
||||
"DELETE FROM alert WHERE dashboard_id = ?",
|
||||
}
|
||||
|
||||
for _, sql := range deletes {
|
||||
|
||||
Reference in New Issue
Block a user