alert_mig.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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",
  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_Text, Nullable: false},
  15. {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false},
  16. {Name: "settings", Type: DB_Text, Nullable: false},
  17. {Name: "frequency", Type: DB_BigInt, Nullable: false},
  18. {Name: "handler", Type: DB_BigInt, Nullable: false},
  19. {Name: "severity", Type: DB_Text, Nullable: false},
  20. {Name: "enabled", Type: DB_Bool, Nullable: false},
  21. {Name: "created", Type: DB_DateTime, Nullable: false},
  22. {Name: "updated", Type: DB_DateTime, Nullable: false},
  23. {Name: "updated_by", Type: DB_BigInt, Nullable: false},
  24. {Name: "created_by", Type: DB_BigInt, Nullable: false},
  25. },
  26. }
  27. // create table
  28. mg.AddMigration("create alert table v1", NewAddTableMigration(alertV1))
  29. alert_state_log := Table{
  30. Name: "alert_state",
  31. Columns: []*Column{
  32. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  33. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  34. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  35. {Name: "state", Type: DB_NVarchar, Length: 50, Nullable: false},
  36. {Name: "info", Type: DB_Text, Nullable: true},
  37. {Name: "triggered_alerts", Type: DB_Text, Nullable: true},
  38. {Name: "created", Type: DB_DateTime, Nullable: false},
  39. },
  40. }
  41. mg.AddMigration("create alert_state_log table v1", NewAddTableMigration(alert_state_log))
  42. alert_heartbeat := Table{
  43. Name: "alert_heartbeat",
  44. Columns: []*Column{
  45. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  46. {Name: "server_id", Type: DB_NVarchar, Length: 50, Nullable: false},
  47. {Name: "created", Type: DB_DateTime, Nullable: false},
  48. {Name: "updated", Type: DB_DateTime, Nullable: false},
  49. },
  50. }
  51. mg.AddMigration("create alert_heartbeat table v1", NewAddTableMigration(alert_heartbeat))
  52. alert_notification := Table{
  53. Name: "alert_notification",
  54. Columns: []*Column{
  55. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  56. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  57. {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  58. {Name: "type", Type: DB_NVarchar, Length: 255, Nullable: false},
  59. {Name: "always_execute", Type: DB_Bool, Nullable: false},
  60. {Name: "settings", Type: DB_Text, Nullable: false},
  61. {Name: "created", Type: DB_DateTime, Nullable: false},
  62. {Name: "updated", Type: DB_DateTime, Nullable: false},
  63. },
  64. }
  65. mg.AddMigration("create alert_notification table v1", NewAddTableMigration(alert_notification))
  66. }