Skip to content

Migrations (v82,v96,v99,v136) remove dependencies #12286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions models/migrations/v136.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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)
}

Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions models/migrations/v82.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 8 additions & 2 deletions models/migrations/v96.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package migrations

import (
"os"
"path"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"

"xorm.io/xorm"
Expand All @@ -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()

Expand Down Expand Up @@ -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
}
}
Expand Down
11 changes: 8 additions & 3 deletions models/migrations/v99.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down