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

v42.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. "fmt"
  7. "code.gitea.io/git"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/log"
  10. "github.com/go-xorm/xorm"
  11. )
  12. // ReleaseV39 describes the added field for Release
  13. type ReleaseV39 struct {
  14. IsTag bool `xorm:"NOT NULL DEFAULT false"`
  15. }
  16. // TableName will be invoked by XORM to customrize the table name
  17. func (*ReleaseV39) TableName() string {
  18. return "release"
  19. }
  20. func releaseAddColumnIsTagAndSyncTags(x *xorm.Engine) error {
  21. if err := x.Sync2(new(ReleaseV39)); err != nil {
  22. return fmt.Errorf("Sync2: %v", err)
  23. }
  24. // For the sake of SQLite3, we can't use x.Iterate here.
  25. offset := 0
  26. pageSize := 20
  27. for {
  28. repos := make([]*models.Repository, 0, pageSize)
  29. if err := x.Table("repository").Asc("id").Limit(pageSize, offset).Find(&repos); err != nil {
  30. return fmt.Errorf("select repos [offset: %d]: %v", offset, err)
  31. }
  32. for _, repo := range repos {
  33. gitRepo, err := git.OpenRepository(repo.RepoPath())
  34. if err != nil {
  35. log.Warn("OpenRepository: %v", err)
  36. continue
  37. }
  38. if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
  39. log.Warn("SyncReleasesWithTags: %v", err)
  40. }
  41. }
  42. if len(repos) < pageSize {
  43. break
  44. }
  45. offset += pageSize
  46. }
  47. return nil
  48. }