alert_mig.go 3.2 KB

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