feat(alerting): renames alert table to alert_rule
This commit is contained in:
@@ -53,7 +53,7 @@ func SaveAlerts(cmd *m.SaveAlertsCommand) error {
|
||||
}
|
||||
|
||||
if missing {
|
||||
_, err = x.Exec("DELETE FROM alert WHERE id = ?", missingAlert.Id)
|
||||
_, err = x.Exec("DELETE FROM alert_rule WHERE id = ?", missingAlert.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -67,30 +67,30 @@ func SaveAlerts(cmd *m.SaveAlertsCommand) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAlertsByDashboardId(dashboardId int64) ([]m.Alert, error) {
|
||||
alerts := make([]m.Alert, 0)
|
||||
func GetAlertsByDashboardId(dashboardId int64) ([]m.AlertRule, error) {
|
||||
alerts := make([]m.AlertRule, 0)
|
||||
err := x.Where("dashboard_id = ?", dashboardId).Find(&alerts)
|
||||
|
||||
if err != nil {
|
||||
return []m.Alert{}, err
|
||||
return []m.AlertRule{}, err
|
||||
}
|
||||
|
||||
return alerts, nil
|
||||
}
|
||||
|
||||
func GetAlertsByDashboardAndPanelId(dashboardId, panelId int64) (m.Alert, error) {
|
||||
func GetAlertsByDashboardAndPanelId(dashboardId, panelId int64) (m.AlertRule, error) {
|
||||
// this code should be refactored!!
|
||||
// uniqueness should be garanted!
|
||||
|
||||
alerts := make([]m.Alert, 0)
|
||||
alerts := make([]m.AlertRule, 0)
|
||||
err := x.Where("dashboard_id = ? and panel_id = ?", dashboardId, panelId).Find(&alerts)
|
||||
|
||||
if err != nil {
|
||||
return m.Alert{}, err
|
||||
return m.AlertRule{}, err
|
||||
}
|
||||
|
||||
if len(alerts) != 1 {
|
||||
return m.Alert{}, err
|
||||
return m.AlertRule{}, err
|
||||
}
|
||||
|
||||
return alerts[0], nil
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
|
||||
testDash := insertTestDashboard("dashboard with alerts", 1, "alert")
|
||||
|
||||
items := []m.Alert{
|
||||
items := []m.AlertRule{
|
||||
{
|
||||
PanelId: 1,
|
||||
DashboardId: testDash.Id,
|
||||
@@ -85,7 +85,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Multiple alerts per dashboard", func() {
|
||||
multipleItems := []m.Alert{
|
||||
multipleItems := []m.AlertRule{
|
||||
{
|
||||
DashboardId: testDash.Id,
|
||||
PanelId: 1,
|
||||
@@ -129,7 +129,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When dashboard is removed", func() {
|
||||
items := []m.Alert{
|
||||
items := []m.AlertRule{
|
||||
{
|
||||
PanelId: 1,
|
||||
DashboardId: testDash.Id,
|
||||
|
||||
@@ -227,7 +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 = ?",
|
||||
"DELETE FROM alert_rule WHERE dashboard_id = ?",
|
||||
}
|
||||
|
||||
for _, sql := range deletes {
|
||||
|
||||
@@ -3,10 +3,8 @@ package migrations
|
||||
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
|
||||
func addAlertMigrations(mg *Migrator) {
|
||||
mg.AddMigration("Drop old table alert table", NewDropTableMigration("alert"))
|
||||
|
||||
alertV1 := Table{
|
||||
Name: "alert",
|
||||
Name: "alert_rule",
|
||||
Columns: []*Column{
|
||||
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||
{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
|
||||
@@ -25,4 +23,16 @@ func addAlertMigrations(mg *Migrator) {
|
||||
|
||||
// create table
|
||||
mg.AddMigration("create alert table v1", NewAddTableMigration(alertV1))
|
||||
|
||||
alert_changes := Table{
|
||||
Name: "alert_rule_updates",
|
||||
Columns: []*Column{
|
||||
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||
{Name: "alert_id", Type: DB_BigInt, Nullable: false},
|
||||
{Name: "org_id", Type: DB_BigInt, Nullable: false},
|
||||
{Name: "created", Type: DB_DateTime, Nullable: false},
|
||||
},
|
||||
}
|
||||
|
||||
mg.AddMigration("create alert_rules_updates table v1", NewAddTableMigration(alert_changes))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user