-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Delete Labels & IssueLabels on Repo Delete too #15039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lafriks
merged 13 commits into
go-gitea:master
from
6543-forks:fix-DB-insonsistenc-again
Mar 19, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
093f6dd
Doctor: find IssueLabels without existing label
6543 da22b79
on Repo Delete: delete labels & issue_labels too
6543 998e421
performance nits
6543 2cf0cbf
Add Migration: Delete orphaned IssueLabels
6543 57560f9
Migration v174: use Sync2
6543 c99cb2c
USE sess !!!
6543 2eda9f7
better func name
6543 d6e5bc1
Merge branch 'master' into fix-DB-insonsistenc-again
6543 26226d6
code format & comment
6543 d643aa3
RAW SQL
6543 51bd328
Update models/migrations/v176.go
6543 3866d81
Merge branch 'master' into fix-DB-insonsistenc-again
6543 68278e5
next try?
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func deleteOrphanedIssueLabels(x *xorm.Engine) error { | ||
type IssueLabel struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
IssueID int64 `xorm:"UNIQUE(s)"` | ||
LabelID int64 `xorm:"UNIQUE(s)"` | ||
} | ||
|
||
sess := x.NewSession() | ||
defer sess.Close() | ||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
|
||
if err := sess.Sync2(new(IssueLabel)); err != nil { | ||
return fmt.Errorf("Sync2: %v", err) | ||
} | ||
|
||
if _, err := sess.Exec(`DELETE FROM issue_label WHERE issue_label.id IN ( | ||
SELECT ill.id FROM ( | ||
SELECT il.id | ||
FROM issue_label AS il | ||
LEFT JOIN label ON il.label_id = label.id | ||
WHERE | ||
label.id IS NULL | ||
) AS ill)`); err != nil { | ||
return err | ||
} | ||
|
||
return sess.Commit() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.