gitea源码

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_16
  4. import (
  5. "xorm.io/xorm"
  6. )
  7. func AddRepoIDForAttachment(x *xorm.Engine) error {
  8. type Attachment struct {
  9. ID int64 `xorm:"pk autoincr"`
  10. UUID string `xorm:"uuid UNIQUE"`
  11. RepoID int64 `xorm:"INDEX"` // this should not be zero
  12. IssueID int64 `xorm:"INDEX"` // maybe zero when creating
  13. ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
  14. UploaderID int64 `xorm:"INDEX DEFAULT 0"`
  15. }
  16. if err := x.Sync(new(Attachment)); err != nil {
  17. return err
  18. }
  19. if _, err := x.Exec("UPDATE `attachment` set repo_id = (SELECT repo_id FROM `issue` WHERE `issue`.id = `attachment`.issue_id) WHERE `attachment`.issue_id > 0"); err != nil {
  20. return err
  21. }
  22. if _, err := x.Exec("UPDATE `attachment` set repo_id = (SELECT repo_id FROM `release` WHERE `release`.id = `attachment`.release_id) WHERE `attachment`.release_id > 0"); err != nil {
  23. return err
  24. }
  25. return nil
  26. }