diff --git a/models/migrations/v136.go b/models/migrations/v136.go index 3f718798ba8..2203f15386c 100644 --- a/models/migrations/v136.go +++ b/models/migrations/v136.go @@ -11,7 +11,6 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -29,7 +28,9 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error { } type PullRequest struct { - ID int64 `xorm:"pk autoincr"` + ID int64 `xorm:"pk autoincr"` + IssueID int64 `xorm:"INDEX"` + Index int64 CommitsAhead int CommitsBehind int @@ -41,7 +42,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error { MergedCommitID string `xorm:"VARCHAR(40)"` } - if err := x.Sync2(new(models.PullRequest)); err != nil { + if err := x.Sync2(new(PullRequest)); err != nil { return fmt.Errorf("Sync2: %v", err) } @@ -64,7 +65,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error { if err := sess.Begin(); err != nil { return err } - var results = make([]*models.PullRequest, 0, batchSize) + var results = make([]*PullRequest, 0, batchSize) err := sess.Where("has_merged = ?", false).OrderBy("id").Limit(batchSize, last).Find(&results) if err != nil { return err diff --git a/models/migrations/v82.go b/models/migrations/v82.go index 2daa86ab073..67bb0cb8c9e 100644 --- a/models/migrations/v82.go +++ b/models/migrations/v82.go @@ -6,9 +6,11 @@ package migrations import ( "fmt" + "path/filepath" + "strings" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/setting" "xorm.io/xorm" ) @@ -32,6 +34,16 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error { Name string } + // UserPath returns the path absolute path of user repositories. + UserPath := func(userName string) string { + return filepath.Join(setting.RepoRootPath, strings.ToLower(userName)) + } + + // RepoPath returns repository path by given user and repository name. + RepoPath := func(userName, repoName string) string { + return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git") + } + // Update release sha1 const batchSize = 100 sess := x.NewSession() @@ -87,7 +99,7 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error { userCache[repo.OwnerID] = user } - gitRepo, err = git.OpenRepository(models.RepoPath(user.Name, repo.Name)) + gitRepo, err = git.OpenRepository(RepoPath(user.Name, repo.Name)) if err != nil { return err } diff --git a/models/migrations/v96.go b/models/migrations/v96.go index 7a1684354ae..9840248f614 100644 --- a/models/migrations/v96.go +++ b/models/migrations/v96.go @@ -6,8 +6,8 @@ package migrations import ( "os" + "path" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/setting" "xorm.io/xorm" @@ -23,6 +23,12 @@ func deleteOrphanedAttachments(x *xorm.Engine) error { CommentID int64 } + // AttachmentLocalPath returns where attachment is stored in local file + // system based on given UUID. + AttachmentLocalPath := func(uuid string) string { + return path.Join(setting.AttachmentPath, uuid[0:1], uuid[1:2], uuid) + } + sess := x.NewSession() defer sess.Close() @@ -52,7 +58,7 @@ func deleteOrphanedAttachments(x *xorm.Engine) error { } for _, attachment := range attachements { - if err := os.RemoveAll(models.AttachmentLocalPath(attachment.UUID)); err != nil { + if err := os.RemoveAll(AttachmentLocalPath(attachment.UUID)); err != nil { return err } } diff --git a/models/migrations/v99.go b/models/migrations/v99.go index 00b4509721e..b6f6babcee7 100644 --- a/models/migrations/v99.go +++ b/models/migrations/v99.go @@ -5,20 +5,25 @@ package migrations import ( - "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" "xorm.io/xorm" ) func addTaskTable(x *xorm.Engine) error { + // TaskType defines task type + type TaskType int + + // TaskStatus defines task status + type TaskStatus int + type Task struct { ID int64 DoerID int64 `xorm:"index"` // operator OwnerID int64 `xorm:"index"` // repo owner id, when creating, the repoID maybe zero RepoID int64 `xorm:"index"` - Type structs.TaskType - Status structs.TaskStatus `xorm:"index"` + Type TaskType + Status TaskStatus `xorm:"index"` StartTime timeutil.TimeStamp EndTime timeutil.TimeStamp PayloadContent string `xorm:"TEXT"`