Skip to content
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

Update issue_index to finish migration #16685

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions models/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,10 @@ func getNextResourceIndex(tableName string, groupID int64) (int64, error) {
}
return curIdx, nil
}

// UpdateResourceIndex is used to set max_index to a specific value.
// !!! Only used to set max_index after repo migration !!!
func UpdateResourceIndex(tableName string, groupID, max int64) error {
_, err := x.Exec(fmt.Sprintf("UPDATE %s SET max_index=? WHERE group_id=?", tableName), max, groupID)
return err
}
7 changes: 7 additions & 0 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,13 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
return opts.Issue.addCrossReferences(e, doer, false)
}

// GetMaxIssueIndex return highest index of an issue based on repo id.
// !!! Only used it to calculate entry for issue_index on repo migration !!!
func GetMaxIssueIndex(repoID int64) (max int64, err error) {
_, err = x.Select(" MAX(`index`)").Table("issue").Where("repo_id=?", repoID).Get(&max)
return
}

// NewIssue creates new issue with labels for repository.
func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
idx, err := GetNextResourceIndex("issue_index", repo.ID)
Expand Down
14 changes: 14 additions & 0 deletions modules/migrations/gitea_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,20 @@ func (g *GiteaLocalUploader) Finish() error {
return ErrRepoNotCreated
}

// update issue_index
max, err := models.GetMaxIssueIndex(g.repo.ID)
if err != nil {
return err
}

if _, err := models.GetNextResourceIndex("issue_index", g.repo.ID); err != nil {
return err
}

if err := models.UpdateResourceIndex("issue_index", g.repo.ID, max); err != nil {
lunny marked this conversation as resolved.
Show resolved Hide resolved
return err
}

g.repo.Status = models.RepositoryReady
return models.UpdateRepositoryCols(g.repo, "status")
}