annotation_mig.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package migrations
  2. import (
  3. . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  4. )
  5. func addAnnotationMig(mg *Migrator) {
  6. table := Table{
  7. Name: "annotation",
  8. Columns: []*Column{
  9. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  10. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  11. {Name: "alert_id", Type: DB_BigInt, Nullable: true},
  12. {Name: "user_id", Type: DB_BigInt, Nullable: true},
  13. {Name: "panel_link_id", Type: DB_NVarchar, Length: 32, Nullable: false},
  14. {Name: "type", Type: DB_NVarchar, Length: 25, Nullable: false},
  15. {Name: "title", Type: DB_Text, Nullable: false},
  16. {Name: "text", Type: DB_Text, Nullable: false},
  17. {Name: "metric", Type: DB_NVarchar, Length: 255, Nullable: true},
  18. {Name: "prev_state", Type: DB_NVarchar, Length: 25, Nullable: false},
  19. {Name: "new_state", Type: DB_NVarchar, Length: 25, Nullable: false},
  20. {Name: "data", Type: DB_Text, Nullable: false},
  21. {Name: "timestamp", Type: DB_DateTime, Nullable: false},
  22. },
  23. Indices: []*Index{
  24. {Cols: []string{"org_id", "alert_id"}, Type: IndexType},
  25. {Cols: []string{"org_id", "type"}, Type: IndexType},
  26. {Cols: []string{"org_id", "panel_link_id"}, Type: IndexType},
  27. {Cols: []string{"timestamp"}, Type: IndexType},
  28. },
  29. }
  30. mg.AddMigration("create annotation table v1", NewAddTableMigration(table))
  31. // create indices
  32. mg.AddMigration("add index annotation org_id & alert_id ", NewAddIndexMigration(table, table.Indices[0]))
  33. mg.AddMigration("add index annotation org_id & type", NewAddIndexMigration(table, table.Indices[1]))
  34. mg.AddMigration("add index annotation org_id & panel_link_id ", NewAddIndexMigration(table, table.Indices[2]))
  35. mg.AddMigration("add index annotation timestamp", NewAddIndexMigration(table, table.Indices[3]))
  36. }