alert_mig.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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: "datasource_name", 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. }