Deleting an entity strategy

To maintain consistency in the system, I can consider 2 removal strategies:

  • cascading deletion of all objects in a relationship;

  • Emulation of deletion (i.e. nothing is deleted from the database, but, for example, the field deletedin essence matters trueand affects the display logic).

I like the second approach, but I don’t know how to implement it correctly.

For example, suppose we are developing a simple blog (users, articles, comments, and other common things). And look at the object User(and the corresponding table User). If we delete a specific user, then his field deletedwill matter true. All user comments will remain where they are, and each reader will still find out who the author of a particular comment is.

All this looks great, but what should I do if a new user (who is trying to register) indicates the same login / email address (other unique fields) that some remote user already has? Theoretically, this unique field value is already free and can be accepted. But what if one day I decide to recover this deleted user?

What are the best practices related to this situation?

+3
source share
2 answers

It depends on your specific needs and requirements for the system with which you work.

Usually in cases like the first part of your example, it is advisable to use the "soft delete" function, even if the user is "Deleted", you do not want their contents to be deleted from the system. However, in this situation, you have a recession that the user account is used forever, and you will not be able to reuse this account for anyone else in the future.

" " , , , .

, , , . , .

+2

, - ( User). , :

A
A B .
A .

, .

0

Source: https://habr.com/ru/post/1756765/


All Articles