Skip to content

Commit b63974e

Browse files
fix migration
1 parent 5ee7ae2 commit b63974e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

models/migrations/v110.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ func addBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
4343
}
4444

4545
var pageSize int64 = 20
46-
totallPRs, err := x.Count(new(models.PullRequest))
46+
qresult, err := sess.QueryInterface("SELECT max(id) as max_id FROM pull_request")
4747
if err != nil {
4848
return err
4949
}
50-
var totalPages int64 = totallPRs / pageSize
50+
var totalPRs int64
51+
totalPRs, ok := qresult[0]["max_id"].(int64)
52+
if !ok {
53+
// This shouldn't happen
54+
return models.ErrNotExist{0}
55+
}
56+
var totalPages int64 = totalPRs / pageSize
5157

5258
// Find latest review of each user in each pull request, and set official field if appropriate
5359
reviews := []*models.Review{}
@@ -61,11 +67,13 @@ func addBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
6167

6268
for _, review := range reviews {
6369
if err := review.LoadAttributes(); err != nil {
64-
return err
70+
// Error might occur if user or issue doesn't exist, ignore it.
71+
continue
6572
}
6673
official, err := models.IsOfficialReviewer(review.Issue, review.Reviewer)
6774
if err != nil {
68-
return err
75+
// Branch might not be proteced or other error, ignore it.
76+
continue
6977
}
7078
review.Official = official
7179

0 commit comments

Comments
 (0)