Skip to content

Commit ce0413f

Browse files
lunnyzeripath
andauthored
Fix migration information update bug when linked github account (#10310)
* Fix bug on upgrade migrated reactions * Fix migration information update bug when linked github account Co-authored-by: zeripath <[email protected]>
1 parent e76a64d commit ce0413f

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

models/issue.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,9 +1873,8 @@ func UpdateIssuesMigrationsByType(gitServiceType structs.GitServiceType, origina
18731873
// UpdateReactionsMigrationsByType updates all migrated repositories' reactions from gitServiceType to replace originalAuthorID to posterID
18741874
func UpdateReactionsMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID string, userID int64) error {
18751875
_, err := x.Table("reaction").
1876-
Join("INNER", "issue", "issue.id = reaction.issue_id").
1877-
Where("issue.repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
1878-
And("reaction.original_author_id = ?", originalAuthorID).
1876+
Where("original_author_id = ?", originalAuthorID).
1877+
And(migratedIssueCond(gitServiceType)).
18791878
Update(map[string]interface{}{
18801879
"user_id": userID,
18811880
"original_author": "",

models/migrate.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,24 @@ func InsertReleases(rels ...*Release) error {
208208
return sess.Commit()
209209
}
210210

211+
func migratedIssueCond(tp structs.GitServiceType) builder.Cond {
212+
return builder.In("issue_id",
213+
builder.Select("issue.id").
214+
From("issue").
215+
InnerJoin("repository", "issue.repo_id = repository.id").
216+
Where(builder.Eq{
217+
"repository.original_service_type": tp,
218+
}),
219+
)
220+
}
221+
211222
// UpdateReviewsMigrationsByType updates reviews' migrations information via given git service type and original id and poster id
212223
func UpdateReviewsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
213224
_, err := x.Table("review").
214-
Where(builder.In("issue_id",
215-
builder.Select("issue.id").
216-
From("issue").
217-
InnerJoin("repository", "issue.repo_id = repository.id").
218-
Where(builder.Eq{
219-
"repository.original_service_type": tp,
220-
}),
221-
)).
222-
And("review.original_author_id = ?", originalAuthorID).
225+
Where("original_author_id = ?", originalAuthorID).
226+
And(migratedIssueCond(tp)).
223227
Update(map[string]interface{}{
224-
"poster_id": posterID,
228+
"reviewer_id": posterID,
225229
"original_author": "",
226230
"original_author_id": 0,
227231
})

0 commit comments

Comments
 (0)