category_mig.go 800 B

123456789101112131415161718192021222324252627
  1. package migrations
  2. import (
  3. . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  4. )
  5. func addAnnotationCategoryMig(mg *Migrator) {
  6. category := Table{
  7. Name: "category",
  8. Columns: []*Column{
  9. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  10. {Name: "org_id", Type: DB_BigInt, Nullable: false},
  11. {Name: "user_id", Type: DB_BigInt, Nullable: true},
  12. {Name: "name", Type: DB_Text, Nullable: false},
  13. {Name: "description", Type: DB_Text, Nullable: false},
  14. },
  15. Indices: []*Index{
  16. {Cols: []string{"org_id", "name"}, Type: IndexType},
  17. },
  18. }
  19. // create table
  20. mg.AddMigration("create category table", NewAddTableMigration(category))
  21. // create indices
  22. mg.AddMigration("add index org_id & name", NewAddIndexMigration(category, category.Indices[0]))
  23. }