Skip to content

Commit 4a8169c

Browse files
committed
update issue_index to finish migration
1 parent 7224cfc commit 4a8169c

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

models/index.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,10 @@ func getNextResourceIndex(tableName string, groupID int64) (int64, error) {
111111
}
112112
return curIdx, nil
113113
}
114+
115+
// UpdateResourceIndex is used to set max_index to a specific value.
116+
// !!! Only used to set max_index after repo migration !!!
117+
func UpdateResourceIndex(tableName string, groupID, max int64) error {
118+
_, err := x.Exec(fmt.Sprintf("UPDATE %s SET max_index=? WHERE group_id=?", tableName), max, groupID)
119+
return err
120+
}

models/issue.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,13 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
982982
return opts.Issue.addCrossReferences(e, doer, false)
983983
}
984984

985+
// GetMaxIssueIndex return highest index of an issue based on repo id.
986+
// !!! Only used it to calculate entry for issue_index on repo migration !!!
987+
func GetMaxIssueIndex(repoID int64) (max int64, err error) {
988+
_, err = x.Select(" MAX(`index`)").Table("issue").Where("repo_id=?", repoID).Get(&max)
989+
return
990+
}
991+
985992
// NewIssue creates new issue with labels for repository.
986993
func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
987994
idx, err := GetNextResourceIndex("issue_index", repo.ID)

modules/migrations/gitea_uploader.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,20 @@ func (g *GiteaLocalUploader) Finish() error {
871871
return ErrRepoNotCreated
872872
}
873873

874+
// update issue_index
875+
max, err := models.GetMaxIssueIndex(g.repo.ID)
876+
if err != nil {
877+
return err
878+
}
879+
880+
if _, err := models.GetNextResourceIndex("issue_index", g.repo.ID); err != nil {
881+
return err
882+
}
883+
884+
if err := models.UpdateResourceIndex("issue_index", g.repo.ID, max); err != nil {
885+
return err
886+
}
887+
874888
g.repo.Status = models.RepositoryReady
875889
return models.UpdateRepositoryCols(g.repo, "status")
876890
}

0 commit comments

Comments
 (0)