You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v193.go 1.1KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2021 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. "xorm.io/xorm"
  7. )
  8. func addRepoIDForAttachment(x *xorm.Engine) error {
  9. type Attachment struct {
  10. ID int64 `xorm:"pk autoincr"`
  11. UUID string `xorm:"uuid UNIQUE"`
  12. RepoID int64 `xorm:"INDEX"` // this should not be zero
  13. IssueID int64 `xorm:"INDEX"` // maybe zero when creating
  14. ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
  15. UploaderID int64 `xorm:"INDEX DEFAULT 0"`
  16. }
  17. if err := x.Sync2(new(Attachment)); err != nil {
  18. return err
  19. }
  20. 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 {
  21. return err
  22. }
  23. 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 {
  24. return err
  25. }
  26. return nil
  27. }