alert_mig.go 3.7 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: "version", Type: DB_BigInt, Nullable: false},
  11. {Name: "dashboard_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: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  15. {Name: "message", Type: DB_Text, Nullable: false},
  16. {Name: "state", Type: DB_NVarchar, Length: 190, Nullable: false},
  17. {Name: "settings", Type: DB_Text, Nullable: false},
  18. {Name: "frequency", Type: DB_BigInt, Nullable: false},
  19. {Name: "handler", Type: DB_BigInt, Nullable: false},
  20. {Name: "severity", Type: DB_Text, Nullable: false},
  21. {Name: "silenced", Type: DB_Bool, Nullable: false},
  22. {Name: "execution_error", Type: DB_Text, Nullable: false},
  23. {Name: "eval_data", Type: DB_Text, Nullable: true},
  24. {Name: "eval_date", Type: DB_DateTime, Nullable: true},
  25. {Name: "new_state_date", Type: DB_DateTime, Nullable: false},
  26. {Name: "state_changes", Type: DB_Int, Nullable: false},
  27. {Name: "created", Type: DB_DateTime, Nullable: false},
  28. {Name: "updated", Type: DB_DateTime, 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: 190, 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 column is_default", NewAddColumnMigration(alert_notification, &Column{
  59. Name: "is_default", Type: DB_Bool, Nullable: false, Default: "0",
  60. }))
  61. mg.AddMigration("add index alert_notification org_id & name", NewAddIndexMigration(alert_notification, alert_notification.Indices[0]))
  62. mg.AddMigration("Update alert table charset", NewTableCharsetMigration("alert", []*Column{
  63. {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  64. {Name: "message", Type: DB_Text, Nullable: false},
  65. {Name: "state", Type: DB_NVarchar, Length: 190, Nullable: false},
  66. {Name: "settings", Type: DB_Text, Nullable: false},
  67. {Name: "severity", Type: DB_Text, Nullable: false},
  68. {Name: "execution_error", Type: DB_Text, Nullable: false},
  69. {Name: "eval_data", Type: DB_Text, Nullable: true},
  70. }))
  71. mg.AddMigration("Update alert_notification table charset", NewTableCharsetMigration("alert_notification", []*Column{
  72. {Name: "name", Type: DB_NVarchar, Length: 190, Nullable: false},
  73. {Name: "type", Type: DB_NVarchar, Length: 255, Nullable: false},
  74. {Name: "settings", Type: DB_Text, Nullable: false},
  75. }))
  76. }