In order to keep consistency in the system I can consider 2 deleting strategy:
cascade deleting of all entities in relationships;
emulating deletion (i.e. nothing is really deleted from DB but, for example, field
deleted
in the entity has valuetrue
and it affects the displaying logic).
I like the second approach but I don't know how to implement it properly.
For example, let's assume we develop a simple blog (users, articles, comments and other usual stuff). And let's look at the User
entity (and a correspondent table USER
). If we delete the certain user then his deleted
field will have value true
. All user's comments would stay where they are and every reader would still know who is the author of a certain comment.
All this looks great but what should I do if a new user (who is trying to register) will specify the same login/email address (other unique fields) as some deleted user already has? Theoretically, this unique field value is already free and can be taken. But, what if one day I would decide to undelete that deleted user?
What are the best practices related to this situation?