diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-11-18 15:23:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-18 22:23:34 +0800 |
commit | 20385b52a3381964b3ab8b1708817b3578a76aca (patch) | |
tree | a500ce8141ab69a6d3b4fd8859467917e52764ce | |
parent | 0b993a0d04c9e542f1584ce00eab7ee4af0321d2 (diff) | |
download | gitea-20385b52a3381964b3ab8b1708817b3578a76aca.tar.gz gitea-20385b52a3381964b3ab8b1708817b3578a76aca.zip |
Prevent dangling user redirects (#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.
-rw-r--r-- | models/user.go | 1 | ||||
-rw-r--r-- | modules/doctor/dbconsistency.go | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/models/user.go b/models/user.go index 85f465127a..0fc28ff055 100644 --- a/models/user.go +++ b/models/user.go @@ -89,6 +89,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) &user_model.UserBadge{UserID: u.ID}, &pull_model.AutoMerge{DoerID: u.ID}, &pull_model.ReviewState{UserID: u.ID}, + &user_model.Redirect{RedirectUserID: u.ID}, ); err != nil { return fmt.Errorf("deleteBeans: %w", err) } diff --git a/modules/doctor/dbconsistency.go b/modules/doctor/dbconsistency.go index 7ae349908e..89d974a350 100644 --- a/modules/doctor/dbconsistency.go +++ b/modules/doctor/dbconsistency.go @@ -205,6 +205,9 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er // find stopwatches without existing issue genericOrphanCheck("Orphaned Stopwatches without existing Issue", "stopwatch", "issue", "stopwatch.issue_id=`issue`.id"), + // find redirects without existing user. + genericOrphanCheck("Orphaned Redirects without existing redirect user", + "user_redirect", "user", "user_redirect.redirect_user_id=`user`.id"), ) for _, c := range consistencyChecks { |