alert_mig.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_BigInt, Nullable: false},
  17. {Name: "warn_operator", Type: DB_NVarchar, Length: 10, Nullable: false},
  18. {Name: "crit_level", Type: DB_BigInt, Nullable: false},
  19. {Name: "crit_operator", Type: DB_NVarchar, Length: 10, Nullable: false},
  20. {Name: "interval", Type: DB_NVarchar, Length: 255, Nullable: false},
  21. {Name: "frequency", Type: DB_BigInt, Nullable: false},
  22. {Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false},
  23. {Name: "description", Type: DB_NVarchar, Length: 255, Nullable: false},
  24. {Name: "query_range", Type: DB_NVarchar, Length: 255, Nullable: false},
  25. {Name: "aggregator", Type: DB_NVarchar, Length: 255, Nullable: false},
  26. {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false},
  27. {Name: "created", Type: DB_DateTime, Nullable: false},
  28. {Name: "updated", Type: DB_DateTime, Nullable: false},
  29. },
  30. }
  31. // create table
  32. mg.AddMigration("create alert_rule table v1", NewAddTableMigration(alertV1))
  33. alert_changes := Table{
  34. Name: "alert_rule_change",
  35. Columns: []*Column{
  36. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  37. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  38. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  39. {Name: "type", Type: DB_NVarchar, Length: 50, Nullable: false},
  40. {Name: "created", Type: DB_DateTime, Nullable: false},
  41. },
  42. }
  43. mg.AddMigration("create alert_rules_updates table v1", NewAddTableMigration(alert_changes))
  44. alert_state_log := Table{
  45. Name: "alert_state",
  46. Columns: []*Column{
  47. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  48. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  49. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  50. {Name: "new_state", Type: DB_NVarchar, Length: 50, Nullable: false},
  51. {Name: "info", Type: DB_Text, Nullable: true},
  52. {Name: "created", Type: DB_DateTime, Nullable: false},
  53. },
  54. }
  55. mg.AddMigration("create alert_state_log table v1", NewAddTableMigration(alert_state_log))
  56. alert_heartbeat := Table{
  57. Name: "alert_heartbeat",
  58. Columns: []*Column{
  59. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  60. {Name: "server_id", Type: DB_NVarchar, Length: 50, 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_heartbeat table v1", NewAddTableMigration(alert_heartbeat))
  66. }