Skip to content

Commit 750ac52

Browse files
authored
Fix Migration 176 yet again (#15131)
* Fix Migration 176 yet again Whilst creating a test for v176 in the migrations_test PR it has become clear that this was still wrong. This is now fixed. Genuinely. Signed-off-by: Andrew Thornton <[email protected]> * and fix repo transfer Signed-off-by: Andrew Thornton <[email protected]>
1 parent f4e677e commit 750ac52

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

models/consistency.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func FixCommentTypeLabelWithEmptyLabel() (int64, error) {
338338

339339
// CountCommentTypeLabelWithOutsideLabels count label comments with outside label
340340
func CountCommentTypeLabelWithOutsideLabels() (int64, error) {
341-
return x.Where("comment.type = ? AND (issue.repo_id != label.repo_id OR (label.repo_id = 0 AND repository.owner_id != label.org_id))", CommentTypeLabel).
341+
return x.Where("comment.type = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id))", CommentTypeLabel).
342342
Table("comment").
343343
Join("inner", "label", "label.id = comment.label_id").
344344
Join("inner", "issue", "issue.id = comment.issue_id ").
@@ -354,8 +354,9 @@ func FixCommentTypeLabelWithOutsideLabels() (int64, error) {
354354
FROM comment AS com
355355
INNER JOIN label ON com.label_id = label.id
356356
INNER JOIN issue on issue.id = com.issue_id
357+
INNER JOIN repository ON issue.repo_id = repository.id
357358
WHERE
358-
com.type = ? AND (issue.repo_id != label.repo_id OR (label.repo_id = 0 AND label.org_id != repo.owner_id))
359+
com.type = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id))
359360
) AS il_too)`, CommentTypeLabel)
360361
if err != nil {
361362
return 0, err
@@ -366,7 +367,7 @@ func FixCommentTypeLabelWithOutsideLabels() (int64, error) {
366367

367368
// CountIssueLabelWithOutsideLabels count label comments with outside label
368369
func CountIssueLabelWithOutsideLabels() (int64, error) {
369-
return x.Where(builder.Expr("issue.repo_id != label.repo_id OR (label.repo_id = 0 AND repository.owner_id != label.org_id)")).
370+
return x.Where(builder.Expr("(label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id)")).
370371
Table("issue_label").
371372
Join("inner", "label", "issue_label.label_id = label.id ").
372373
Join("inner", "issue", "issue.id = issue_label.issue_id ").
@@ -384,7 +385,7 @@ func FixIssueLabelWithOutsideLabels() (int64, error) {
384385
INNER JOIN issue on issue.id = il_too_too.issue_id
385386
INNER JOIN repository on repository.id = issue.repo_id
386387
WHERE
387-
issue.repo_id != label.repo_id OR (label.repo_id = 0 AND label.org_id != repository.owner_id)
388+
(label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id)
388389
) AS il_too )`)
389390

390391
if err != nil {

models/migrations/v176.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func removeInvalidLabels(x *xorm.Engine) error {
5252
INNER JOIN issue on issue.id = il_too_too.issue_id
5353
INNER JOIN repository on repository.id = issue.repo_id
5454
WHERE
55-
issue.repo_id != label.repo_id OR (label.repo_id = 0 AND label.org_id != repository.owner_id)
55+
(label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id)
5656
) AS il_too )`); err != nil {
5757
return err
5858
}
@@ -65,7 +65,7 @@ func removeInvalidLabels(x *xorm.Engine) error {
6565
INNER JOIN issue on issue.id = com.issue_id
6666
INNER JOIN repository on repository.id = issue.repo_id
6767
WHERE
68-
com.type = ? AND (issue.repo_id != label.repo_id OR (label.repo_id = 0 AND label.org_id != repository.owner_id))
68+
com.type = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id))
6969
) AS il_too)`, 7); err != nil {
7070
return err
7171
}

models/repo_transfer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) (err e
333333
INNER JOIN label ON il_too_too.label_id = label.id
334334
INNER JOIN issue on issue.id = il_too_too.issue_id
335335
WHERE
336-
issue.repo_id = ? AND (issue.repo_id != label.repo_id OR (label.repo_id = 0 AND label.org_id != ?))
336+
issue.repo_id = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != ?))
337337
) AS il_too )`, repo.ID, newOwner.ID); err != nil {
338338
return fmt.Errorf("Unable to remove old org labels: %v", err)
339339
}
@@ -343,9 +343,9 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) (err e
343343
SELECT com.id
344344
FROM comment AS com
345345
INNER JOIN label ON com.label_id = label.id
346-
INNER JOIN issue on issue.id = com.issue_id
346+
INNER JOIN issue ON issue.id = com.issue_id
347347
WHERE
348-
com.type = ? AND issue.repo_id = ? AND (issue.repo_id != label.repo_id OR (label.repo_id = 0 AND label.org_id != ?))
348+
com.type = ? AND issue.repo_id = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != ?))
349349
) AS il_too)`, CommentTypeLabel, repo.ID, newOwner.ID); err != nil {
350350
return fmt.Errorf("Unable to remove old org label comments: %v", err)
351351
}

0 commit comments

Comments
 (0)