alert_mig.go 2.9 KB

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