alert_mig.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. func addAlertMigrations(mg *Migrator) {
  4. alertV1 := Table{
  5. Name: "alert_rule",
  6. Columns: []*Column{
  7. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  8. {Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
  9. {Name: "panel_id", Type: DB_BigInt, Nullable: false},
  10. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  11. {Name: "query", Type: DB_Text, Nullable: false},
  12. {Name: "query_ref_id", Type: DB_NVarchar, Length: 255, Nullable: false},
  13. {Name: "warn_level", Type: DB_NVarchar, Length: 255, Nullable: false},
  14. {Name: "crit_level", Type: DB_NVarchar, Length: 255, Nullable: false},
  15. {Name: "interval", Type: DB_NVarchar, Length: 255, Nullable: false},
  16. {Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false},
  17. {Name: "description", Type: DB_NVarchar, Length: 255, Nullable: false},
  18. {Name: "query_range", Type: DB_NVarchar, Length: 255, Nullable: false},
  19. {Name: "aggregator", Type: DB_NVarchar, Length: 255, Nullable: false},
  20. {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false},
  21. },
  22. }
  23. // create table
  24. mg.AddMigration("create alert_rule table v1", NewAddTableMigration(alertV1))
  25. alert_changes := Table{
  26. Name: "alert_rule_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_rules_updates table v1", NewAddTableMigration(alert_changes))
  36. alert_state_log := Table{
  37. Name: "alert_state_log",
  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. }