alert_mig.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. },
  21. }
  22. // create table
  23. mg.AddMigration("create alert_rule table v1", NewAddTableMigration(alertV1))
  24. alert_changes := Table{
  25. Name: "alert_rule_change",
  26. Columns: []*Column{
  27. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  28. {Name: "alert_id", Type: DB_BigInt, Nullable: false},
  29. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  30. {Name: "type", Type: DB_NVarchar, Length: 50, Nullable: false},
  31. {Name: "created", Type: DB_DateTime, Nullable: false},
  32. },
  33. }
  34. mg.AddMigration("create alert_rules_updates table v1", NewAddTableMigration(alert_changes))
  35. }