Repository navigation
fix(admin): purge soft-deleted users after a grace period (#99) - #102
Merged
Merged
Conversation
Soft-deleted users kept their email reserved forever: the purge job that migration 028 promised never existed, and admin_audit_log.target_id's FK made every soft-deleted user impossible to hard-delete, force-delete included, because soft delete audits the user as target. - 055 drops that FK so the audit trail outlives the user. - user_purge hard-deletes users soft-deleted longer than USER_PURGE_GRACE_DAYS (default 30), at boot and daily, auditing each. - A user other rows still reference (team owner, shared-object author) cannot be deleted; their email is rewritten to <id>@purged.invalid so the address is free, and restore then refuses with 409. Migration 028's comment is left as is: sqlx checksums applied migrations. Closes #99 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kipavy
force-pushed
the
fix/purge-soft-deleted-users
branch
from
October 8, 2026 11:52
c6c23fd to
63ad4d9
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #99.
Problem
Soft-deleted users kept their email reserved forever. Two causes:
admin_audit_log.target_idreferencedusers(id)with noON DELETEaction. Soft delete writes an audit row targeting the user, so no soft-deleted user could ever be hard-deleted, not even with force-delete.Changes
migrations/055_admin_audit_target_no_fk.sqldrops that FK. Nothing joins the audit log tousers, and the trail should outlive the user.src/user_purge.rsaddspurge_expired, which runs at boot and in the daily retention loop. For each user soft-deleted longer ago thanUSER_PURGE_GRACE_DAYS(default 30):purge_useraudit row in the same transaction.<id>@purged.invalidand write apurge_user_release_emailaudit row once. The delete is retried on later runs.restore_userreturns 409 once the email has been released.USER_PURGE_GRACE_DAYSis documented in.env.exampleand passed throughcompose.yml.Migration 028's comment is left unchanged because sqlx checksums applied migrations and editing it would make boot fail.
Deploy note
The first boot purges every user already soft-deleted more than 30 days ago.
Tests
cargo test --all-targets(683 passed) andcargo clippy --all-targets -- -D warningspass locally.🤖 Generated with Claude Code