alert_mig.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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: "panel_id", Type: DB_BigInt, Nullable: false},
  12. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  13. {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  14. {Name: "description", Type: DB_NVarchar, Length: 255, Nullable: false},
  15. {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false},
  16. {Name: "expression", Type: DB_Text, Nullable: false},
  17. {Name: "created", Type: DB_DateTime, Nullable: false},
  18. {Name: "updated", Type: DB_DateTime, Nullable: false},
  19. },
  20. }
  21. // create table
  22. mg.AddMigration("create alert_rule table v2", NewAddTableMigration(alertV1))
  23. alert_changes := Table{
  24. Name: "alert_rule_change",
  25. Columns: []*Column{
  26. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  27. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  28. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  29. {Name: "type", Type: DB_NVarchar, Length: 50, Nullable: false},
  30. {Name: "created", Type: DB_DateTime, Nullable: false},
  31. },
  32. }
  33. mg.AddMigration("create alert_rules_updates table v1", NewAddTableMigration(alert_changes))
  34. alert_state_log := Table{
  35. Name: "alert_state",
  36. Columns: []*Column{
  37. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  38. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  39. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  40. {Name: "new_state", Type: DB_NVarchar, Length: 50, Nullable: false},
  41. {Name: "info", Type: DB_Text, Nullable: true},
  42. {Name: "created", Type: DB_DateTime, Nullable: false},
  43. },
  44. }
  45. mg.AddMigration("create alert_state_log table v1", NewAddTableMigration(alert_state_log))
  46. alert_heartbeat := Table{
  47. Name: "alert_heartbeat",
  48. Columns: []*Column{
  49. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  50. {Name: "server_id", Type: DB_NVarchar, Length: 50, Nullable: false},
  51. {Name: "created", Type: DB_DateTime, Nullable: false},
  52. {Name: "updated", Type: DB_DateTime, Nullable: false},
  53. },
  54. }
  55. mg.AddMigration("create alert_heartbeat table v1", NewAddTableMigration(alert_heartbeat))
  56. }