code.gitea.io/gitea@v1.21.7/models/migrations/v1_16/v193.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package v1_16 //nolint 5 6 import ( 7 "xorm.io/xorm" 8 ) 9 10 func AddRepoIDForAttachment(x *xorm.Engine) error { 11 type Attachment struct { 12 ID int64 `xorm:"pk autoincr"` 13 UUID string `xorm:"uuid UNIQUE"` 14 RepoID int64 `xorm:"INDEX"` // this should not be zero 15 IssueID int64 `xorm:"INDEX"` // maybe zero when creating 16 ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating 17 UploaderID int64 `xorm:"INDEX DEFAULT 0"` 18 } 19 if err := x.Sync(new(Attachment)); err != nil { 20 return err 21 } 22 23 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 { 24 return err 25 } 26 27 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 { 28 return err 29 } 30 31 return nil 32 }