Skip to content

Commit

Permalink
fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsvantesson committed Nov 26, 2019
1 parent 5ee7ae2 commit b63974e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions models/migrations/v110.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ func addBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
}

var pageSize int64 = 20
totallPRs, err := x.Count(new(models.PullRequest))
qresult, err := sess.QueryInterface("SELECT max(id) as max_id FROM pull_request")
if err != nil {
return err
}
var totalPages int64 = totallPRs / pageSize
var totalPRs int64
totalPRs, ok := qresult[0]["max_id"].(int64)
if !ok {
// This shouldn't happen
return models.ErrNotExist{0}
}
var totalPages int64 = totalPRs / pageSize

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

for _, review := range reviews {
if err := review.LoadAttributes(); err != nil {
return err
// Error might occur if user or issue doesn't exist, ignore it.
continue
}
official, err := models.IsOfficialReviewer(review.Issue, review.Reviewer)
if err != nil {
return err
// Branch might not be proteced or other error, ignore it.
continue
}
review.Official = official

Expand Down

0 comments on commit b63974e

Please sign in to comment.