Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gpanos's avatar

Getting rid of soft deletes?

Hey all, A lot of people advocate that soft deleting is "bad". You lose data integrity, you have to include where clauses or partition your tables, GDPR issues etc. I myself felt all of this while implementing soft deletes in a big e-commerce site. The only reason that soft deletes were implemented in the project is to be able to display metrics and generate reports without loosing any data. There was never a situation that we had to restore a soft deleted record for some reason and I feel that reporting shouldn't affect how the data is structured.

I know that there should be a better way to handle metrics/reporting: For example: Display the GMV total which is calculated by the sum of the paid bookings. If I drop the soft deletes hard deleting a user account would mean that the GMV can be potentially affected since the bookings of this user would be deleted too.

I can potentially write to another table by using triggers but a booking has a pretty complicated lifecycle and seems a pain to handle all this in the software.

Do you guys have any experience in this? Is there maybe an external tool that can handle this in the database layer ?

Thanks a lot.

0 likes
1 reply
Snapey's avatar

A possible approach is to anonymise the data instead of deleting? EG if its a user account, wipe the email and password fields, and set the username to anon{$id} inserting the id. You can then keep related data like orders and know they were by a specific person, but not who that is in the real world.

Please or to participate in this conversation.