team_mig.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. func addTeamMigrations(mg *Migrator) {
  4. teamV1 := Table{
  5. Name: "team",
  6. Columns: []*Column{
  7. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  8. {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
  9. {Name: "org_id", Type: DB_BigInt},
  10. {Name: "created", Type: DB_DateTime, Nullable: false},
  11. {Name: "updated", Type: DB_DateTime, Nullable: false},
  12. },
  13. Indices: []*Index{
  14. {Cols: []string{"org_id"}},
  15. {Cols: []string{"org_id", "name"}, Type: UniqueIndex},
  16. },
  17. }
  18. mg.AddMigration("create team table", NewAddTableMigration(teamV1))
  19. //------- indexes ------------------
  20. mg.AddMigration("add index team.org_id", NewAddIndexMigration(teamV1, teamV1.Indices[0]))
  21. mg.AddMigration("add unique index team_org_id_name", NewAddIndexMigration(teamV1, teamV1.Indices[1]))
  22. teamMemberV1 := Table{
  23. Name: "team_member",
  24. Columns: []*Column{
  25. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  26. {Name: "org_id", Type: DB_BigInt},
  27. {Name: "team_id", Type: DB_BigInt},
  28. {Name: "user_id", Type: DB_BigInt},
  29. {Name: "created", Type: DB_DateTime, Nullable: false},
  30. {Name: "updated", Type: DB_DateTime, Nullable: false},
  31. },
  32. Indices: []*Index{
  33. {Cols: []string{"org_id"}},
  34. {Cols: []string{"org_id", "team_id", "user_id"}, Type: UniqueIndex},
  35. },
  36. }
  37. mg.AddMigration("create team member table", NewAddTableMigration(teamMemberV1))
  38. //------- indexes ------------------
  39. mg.AddMigration("add index team_member.org_id", NewAddIndexMigration(teamMemberV1, teamMemberV1.Indices[0]))
  40. mg.AddMigration("add unique index team_member_org_id_team_id_user_id", NewAddIndexMigration(teamMemberV1, teamMemberV1.Indices[1]))
  41. }