-
Notifications
You must be signed in to change notification settings - Fork 100
feat: soft delete user #2776
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
feat: soft delete user #2776
Conversation
await queryRunner.query( | ||
`DROP RULE prototect_ghostuser_deletion on "user";`, | ||
); | ||
await queryRunner.query(` | ||
CREATE OR REPLACE FUNCTION prevent_special_user_delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of RULE
create trigger, because RULE
was blocking usage of RETURNING
in zombie cron.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements soft deletion for users by preserving deleted user IDs, checking for collisions during user creation, and handling zombie user cleanup. Key changes include:
- Adding a new telemetry metric counter for deleted user collisions.
- Creating migrations for a DeletedUser table and a trigger to prevent deletion of special users.
- Updating user logic and error handling to support soft deletion and collision detection.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/telemetry/metrics.ts | Adds metric counter for tracking deleted user collisions. |
src/migration/1744972478032-SpecialUserDeleteTrigger.ts | Creates trigger to prevent deletion of special users; includes a potential condition inconsistency and naming typo. |
src/migration/1744965354822-DeletedUser.ts | Creates the DeletedUser table for storing soft deleted user records. |
src/errors.ts | Adds a new DeletedUserCollisionError and updates error enums. |
src/entity/user/utils.ts | Enhances safeInsertUser logic to check for deleted users and handle collisions. |
src/entity/user/DeletedUser.ts | Defines the DeletedUser entity for soft delete implementation. |
src/cron/cleanZombieUsers.ts | Updates zombie user cleanup to insert records into DeletedUser. |
src/common/user.ts | Modifies deleteUser to insert a DeletedUser record after deletion. |
tests/private.ts | Adds tests to verify handling of deleted user collisions during user creation. |
tests/cron/cleanZombieUsers.ts | Adds tests ensuring deleted user records are created during zombie cleanup. |
Comments suppressed due to low confidence (1)
src/migration/1744972478032-SpecialUserDeleteTrigger.ts:10
- [nitpick] The rule name 'prototect_ghostuser_deletion' may be a typo; consider renaming it to 'protect_ghostuser_deletion' for clarity.
`DROP RULE prototect_ghostuser_deletion on "user";`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens in the user_transaction table? Does the rows get deleted?
yes, as other user content, njord keeps the log though, although @idoshamun wdyt, should we move user_transaction items to ghost user instead of cascading when user is deleted? |
I think we should update it to ghost user, so the receiver still can see awards they've been given. |
@omBratteng yeah I agree, see 9402bb6 |
9402bb6
to
96ff01a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
@idoshamun ready for review again 🙏 |
safeInsertUser