team_mig.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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: 190, 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. // add column email
  42. mg.AddMigration("Add column email to team table", NewAddColumnMigration(teamV1, &Column{
  43. Name: "email", Type: DB_NVarchar, Nullable: true, Length: 190,
  44. }))
  45. mg.AddMigration("Add column external to team_member table", NewAddColumnMigration(teamMemberV1, &Column{
  46. Name: "external", Type: DB_Bool, Nullable: true,
  47. }))
  48. mg.AddMigration("Add column permission to team_member table", NewAddColumnMigration(teamMemberV1, &Column{
  49. Name: "permission", Type: DB_SmallInt, Nullable: true,
  50. }))
  51. }