Skip to content

Commit af8b225

Browse files
author
Gusted
authored
Prevent dangling user redirects (#21856) (#21858)
- Backport #21856 - It's possible that the `user_redirect` table contains a user id that no longer exists. - Delete a user redirect upon deleting the user. - Add a check for these dangling user redirects to check-db-consistency.
1 parent 8917af8 commit af8b225

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Diff for: models/user.go

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
8989
&user_model.UserBadge{UserID: u.ID},
9090
&pull_model.AutoMerge{DoerID: u.ID},
9191
&pull_model.ReviewState{UserID: u.ID},
92+
&user_model.Redirect{RedirectUserID: u.ID},
9293
); err != nil {
9394
return fmt.Errorf("deleteBeans: %w", err)
9495
}

Diff for: modules/doctor/dbconsistency.go

+3
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
205205
// find stopwatches without existing issue
206206
genericOrphanCheck("Orphaned Stopwatches without existing Issue",
207207
"stopwatch", "issue", "stopwatch.issue_id=`issue`.id"),
208+
// find redirects without existing user.
209+
genericOrphanCheck("Orphaned Redirects without existing redirect user",
210+
"user_redirect", "user", "user_redirect.redirect_user_id=`user`.id"),
208211
)
209212

210213
for _, c := range consistencyChecks {

0 commit comments

Comments
 (0)