alert_mig.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. func addAlertMigrations(mg *Migrator) {
  4. alertV1 := Table{
  5. Name: "alert_rule",
  6. Columns: []*Column{
  7. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  8. {Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
  9. {Name: "panel_id", Type: DB_BigInt, Nullable: false},
  10. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  11. {Name: "query", Type: DB_Text, Nullable: false},
  12. {Name: "query_ref_id", Type: DB_NVarchar, Length: 255, Nullable: false},
  13. {Name: "warn_level", Type: DB_BigInt, Nullable: false},
  14. {Name: "warn_operator", Type: DB_NVarchar, Length: 10, Nullable: false},
  15. {Name: "crit_level", Type: DB_BigInt, Nullable: false},
  16. {Name: "crit_operator", Type: DB_NVarchar, Length: 10, Nullable: false},
  17. {Name: "interval", Type: DB_NVarchar, Length: 255, Nullable: false},
  18. {Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false},
  19. {Name: "description", Type: DB_NVarchar, Length: 255, Nullable: false},
  20. {Name: "query_range", Type: DB_NVarchar, Length: 255, Nullable: false},
  21. {Name: "aggregator", Type: DB_NVarchar, Length: 255, Nullable: false},
  22. {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false},
  23. },
  24. }
  25. // create table
  26. mg.AddMigration("create alert_rule table v1", NewAddTableMigration(alertV1))
  27. alert_changes := Table{
  28. Name: "alert_rule_change",
  29. Columns: []*Column{
  30. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  31. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  32. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  33. {Name: "type", Type: DB_NVarchar, Length: 50, Nullable: false},
  34. {Name: "created", Type: DB_DateTime, Nullable: false},
  35. },
  36. }
  37. mg.AddMigration("create alert_rules_updates table v1", NewAddTableMigration(alert_changes))
  38. alert_state_log := Table{
  39. Name: "alert_state_log",
  40. Columns: []*Column{
  41. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  42. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  43. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  44. {Name: "new_state", Type: DB_NVarchar, Length: 50, Nullable: false},
  45. {Name: "info", Type: DB_Text, Nullable: true},
  46. {Name: "created", Type: DB_DateTime, Nullable: false},
  47. },
  48. }
  49. mg.AddMigration("create alert_state_log table v1", NewAddTableMigration(alert_state_log))
  50. }