alert_mig.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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: "handler", Type: DB_BigInt, Nullable: false},
  18. {Name: "enabled", Type: DB_Bool, Nullable: false},
  19. {Name: "created", Type: DB_DateTime, Nullable: false},
  20. {Name: "updated", Type: DB_DateTime, Nullable: false},
  21. },
  22. }
  23. // create table
  24. mg.AddMigration("create alert table v1", NewAddTableMigration(alertV1))
  25. alert_changes := Table{
  26. Name: "alert_change",
  27. Columns: []*Column{
  28. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  29. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  30. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  31. {Name: "type", Type: DB_NVarchar, Length: 50, Nullable: false},
  32. {Name: "created", Type: DB_DateTime, Nullable: false},
  33. },
  34. }
  35. mg.AddMigration("create alert_change table v1", NewAddTableMigration(alert_changes))
  36. alert_state_log := Table{
  37. Name: "alert_state",
  38. Columns: []*Column{
  39. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  40. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  41. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  42. {Name: "new_state", Type: DB_NVarchar, Length: 50, Nullable: false},
  43. {Name: "info", Type: DB_Text, Nullable: true},
  44. {Name: "created", Type: DB_DateTime, Nullable: false},
  45. },
  46. }
  47. mg.AddMigration("create alert_state_log table v1", NewAddTableMigration(alert_state_log))
  48. alert_heartbeat := Table{
  49. Name: "alert_heartbeat",
  50. Columns: []*Column{
  51. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  52. {Name: "server_id", Type: DB_NVarchar, Length: 50, Nullable: false},
  53. {Name: "created", Type: DB_DateTime, Nullable: false},
  54. {Name: "updated", Type: DB_DateTime, Nullable: false},
  55. },
  56. }
  57. mg.AddMigration("create alert_heartbeat table v1", NewAddTableMigration(alert_heartbeat))
  58. }