Fix bug on migration 147 (#12565)
parent
7a8a05cc44
commit
2026d885d6
|
@ -82,14 +82,15 @@ func createReviewsForCodeComments(x *xorm.Engine) error {
|
|||
if err := x.Sync2(new(Review), new(Comment)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var updateComment = func(comments []*Comment) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := sess.Where("review_id = 0 and type = 21").Iterate(new(Comment), func(idx int, bean interface{}) error {
|
||||
comment := bean.(*Comment)
|
||||
|
||||
for _, comment := range comments {
|
||||
review := &Review{
|
||||
Type: ReviewTypeComment,
|
||||
ReviewerID: comment.PosterID,
|
||||
|
@ -122,11 +123,32 @@ func createReviewsForCodeComments(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
comment.ReviewID = review.ID
|
||||
_, err := sess.ID(comment.ID).Cols("review_id").NoAutoTime().Update(comment)
|
||||
return err
|
||||
}); err != nil {
|
||||
if _, err := sess.ID(comment.ID).Cols("review_id").NoAutoTime().Update(comment); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
var start = 0
|
||||
var batchSize = 100
|
||||
for {
|
||||
var comments = make([]*Comment, 0, batchSize)
|
||||
if err := x.Where("review_id = 0 and type = 21").Limit(batchSize, start).Find(&comments); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := updateComment(comments); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
start += len(comments)
|
||||
|
||||
if len(comments) < batchSize {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue