Working on a project at the moment and we have to implement soft deletion for the majority of users (user roles). We decided to add an is_deleted='0'
field on each table in the database and set it to '1'
if particular user roles hit a delete button on a specific record.
For future maintenance now, each SELECT
query will need to ensure they do not include records where is_deleted='1'
.
Is there a better solution for implementing soft deletion?
Update: I should also note that we have an Audit database that tracks changes (field, old value, new value, time, user, ip) to all tables/fields within the Application database.
To restore the soft-deleted DB, it must first be undeleted. To undelete, choose the soft-deleted DB, and then select the option Undelete. A window will appear warning that if undelete is chosen, all restore points for the database will be undeleted and available for performing a restore operation.
The Soft Delete feature allows you to flag entities as deleted (Soft Delete) instead of deleting them physically (Hard Delete). The soft delete feature can be achieved by using the 'IEFSoftDelete' interface. By default, this interface is always added to the manager.
Now, we can soft delete a comment by calling #destroy . In the next step we add the default scope which will exclude all deleted comments. And create only_deleted and with_deleted scopes. Now, we can soft delete comments and query non-deleted and deleted comments.
I would lean towards a deleted_at
column that contains the datetime of when the deletion took place. Then you get a little bit of free metadata about the deletion. For your SELECT
just get rows WHERE deleted_at IS NULL
You could perform all of your queries against a view that contains the WHERE IS_DELETED='0'
clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With