Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

v38.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "github.com/go-xorm/xorm"
  8. )
  9. func removeCommitsUnitType(x *xorm.Engine) (err error) {
  10. // Update team unit types
  11. const batchSize = 100
  12. for start := 0; ; start += batchSize {
  13. teams := make([]*models.Team, 0, batchSize)
  14. if err := x.Limit(batchSize, start).Find(&teams); err != nil {
  15. return err
  16. }
  17. if len(teams) == 0 {
  18. break
  19. }
  20. for _, team := range teams {
  21. ut := make([]models.UnitType, 0, len(team.UnitTypes))
  22. for _, u := range team.UnitTypes {
  23. if u < V16UnitTypeCommits {
  24. ut = append(ut, u)
  25. } else if u > V16UnitTypeSettings {
  26. ut = append(ut, u-2)
  27. } else if u > V16UnitTypeCommits && u != V16UnitTypeSettings {
  28. ut = append(ut, u-1)
  29. }
  30. }
  31. team.UnitTypes = ut
  32. if _, err := x.Id(team.ID).Cols("unit_types").Update(team); err != nil {
  33. return err
  34. }
  35. }
  36. }
  37. // Delete commits and settings unit types
  38. if _, err = x.In("`type`", []models.UnitType{V16UnitTypeCommits, V16UnitTypeSettings}).Delete(new(RepoUnit)); err != nil {
  39. return err
  40. }
  41. // Fix renumber unit types that where in enumeration after settings unit type
  42. if _, err = x.Where("`type` > ?", V16UnitTypeSettings).Decr("type").Decr("index").Update(new(RepoUnit)); err != nil {
  43. return err
  44. }
  45. // Fix renumber unit types that where in enumeration after commits unit type
  46. if _, err = x.Where("`type` > ?", V16UnitTypeCommits).Decr("type").Decr("index").Update(new(RepoUnit)); err != nil {
  47. return err
  48. }
  49. return nil
  50. }