annotation_mig.go 1.9 KB

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