문제

As always, I apologize if this question has been discussed somewhere.

I'm curious for some insight on how everyone is handling related tables and assets when a user is deleted. The project I'm currently working on is mostly a project management / issue tracking system.

When a user is deleted what should happen to their issues, projects, files, etc..? A few scenarios off the top of my head were to either:

  • Delete all their issues, files, projects, etc...
  • Reparent everything to the only (or one of many) admin user
  • Lock the user account but keep all their assets (but I may need to REALLY delete them at some point if server storage becomes an issue)
  • Assign a non-existent user_id (0) to related tables (This seems like it would be too problematic when trying to JOIN tables

Any other possible considerations I'm missing? The third solution sounds the best to me right now. Those of you who've worked on large projects, how have you handled deleting users? On a side note, I'm developing the project in php (yii) and mysql.

도움이 되었습니까?

해결책 2

Actually deleting a user and related objects should be the last thing you do. Even a deleted user is historical and useful data. You can always archive it if it truly becomes burdensome.

As recommended by Lukas, deactivate the user instead. All of your queries that request user-related objects should then check the 'active' flag to include/exclude the user. When you have that complex join query to retrieve the data, it saves a lot of effort and processing with that flag.

When it comes to 'actual' assets, like a file, those can take up a lot of space, but if they are related to a inactive user, you should not delete those either. Archive again, if necessary. It may require adding an 'archived' flag to an entry pointing to that asset, so that you're not trying to open the file when it does not exist.

다른 팁

You should delete all data that is not used by other users.

Because of situations in which other users are affected, like issues or tasks, you should just deactivate the user profile. The best way doing this is by adding a column 'active' to the database and set it to 0 if the user gets deleted. In your system, you can parse this column and display something like 'Deleted user'.

If no one else is assigned to a task, it would be the best if you let them unassigned and make something like a pool in which other users can choose tasks or get assigned to tasks.

The same way I'd do it with other data like projects.

Concerning files it does make sense to delete them if they are not required by anything any more.

Always remember, it's better to have some more data on the server than loosing important information!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top