alert_mig.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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: "message", 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: "paused", Type: DB_Bool, Nullable: false},
  21. {Name: "silenced", Type: DB_Bool, Nullable: false},
  22. {Name: "execution_error", Type: DB_Text, Nullable: false},
  23. {Name: "last_eval_data", Type: DB_Text, Nullable: false},
  24. {Name: "last_eval_time", Type: DB_DateTime, Nullable: false},
  25. {Name: "created", Type: DB_DateTime, Nullable: false},
  26. {Name: "updated", Type: DB_DateTime, Nullable: false},
  27. {Name: "updated_by", Type: DB_BigInt, Nullable: false},
  28. {Name: "created_by", Type: DB_BigInt, Nullable: false},
  29. },
  30. Indices: []*Index{
  31. {Cols: []string{"org_id", "id"}, Type: IndexType},
  32. {Cols: []string{"state"}, Type: IndexType},
  33. {Cols: []string{"dashboard_id"}, Type: IndexType},
  34. },
  35. }
  36. // create table
  37. mg.AddMigration("create alert table v1", NewAddTableMigration(alertV1))
  38. // create indices
  39. mg.AddMigration("add index alert org_id & id ", NewAddIndexMigration(alertV1, alertV1.Indices[0]))
  40. mg.AddMigration("add index alert state", NewAddIndexMigration(alertV1, alertV1.Indices[1]))
  41. mg.AddMigration("add index alert dashboard_id", NewAddIndexMigration(alertV1, alertV1.Indices[2]))
  42. alert_notification := Table{
  43. Name: "alert_notification",
  44. Columns: []*Column{
  45. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  46. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  47. {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  48. {Name: "type", Type: DB_NVarchar, Length: 255, Nullable: false},
  49. {Name: "settings", Type: DB_Text, Nullable: false},
  50. {Name: "created", Type: DB_DateTime, Nullable: false},
  51. {Name: "updated", Type: DB_DateTime, Nullable: false},
  52. },
  53. Indices: []*Index{
  54. {Cols: []string{"org_id", "name"}, Type: UniqueIndex},
  55. },
  56. }
  57. mg.AddMigration("create alert_notification table v1", NewAddTableMigration(alert_notification))
  58. mg.AddMigration("add index alert_notification org_id & name", NewAddIndexMigration(alert_notification, alert_notification.Indices[0]))
  59. }