annotation_mig.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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: "dashboard_id", Type: DB_BigInt, Nullable: true},
  14. {Name: "panel_id", Type: DB_BigInt, Nullable: true},
  15. {Name: "category_id", Type: DB_BigInt, Nullable: true},
  16. {Name: "type", Type: DB_NVarchar, Length: 25, Nullable: false},
  17. {Name: "title", Type: DB_Text, Nullable: false},
  18. {Name: "text", Type: DB_Text, Nullable: false},
  19. {Name: "metric", Type: DB_NVarchar, Length: 255, Nullable: true},
  20. {Name: "prev_state", Type: DB_NVarchar, Length: 25, Nullable: false},
  21. {Name: "new_state", Type: DB_NVarchar, Length: 25, Nullable: false},
  22. {Name: "data", Type: DB_Text, Nullable: false},
  23. {Name: "epoch", Type: DB_BigInt, Nullable: false},
  24. },
  25. Indices: []*Index{
  26. {Cols: []string{"org_id", "alert_id"}, Type: IndexType},
  27. {Cols: []string{"org_id", "type"}, Type: IndexType},
  28. {Cols: []string{"org_id", "category_id"}, Type: IndexType},
  29. {Cols: []string{"org_id", "dashboard_id", "panel_id", "epoch"}, Type: IndexType},
  30. {Cols: []string{"org_id", "epoch"}, Type: IndexType},
  31. },
  32. }
  33. mg.AddMigration("Drop old annotation table v4", NewDropTableMigration("annotation"))
  34. mg.AddMigration("create annotation table v5", NewAddTableMigration(table))
  35. // create indices
  36. mg.AddMigration("add index annotation 0 v3", NewAddIndexMigration(table, table.Indices[0]))
  37. mg.AddMigration("add index annotation 1 v3", NewAddIndexMigration(table, table.Indices[1]))
  38. mg.AddMigration("add index annotation 2 v3", NewAddIndexMigration(table, table.Indices[2]))
  39. mg.AddMigration("add index annotation 3 v3", NewAddIndexMigration(table, table.Indices[3]))
  40. mg.AddMigration("add index annotation 4 v3", NewAddIndexMigration(table, table.Indices[4]))
  41. }