Soft Deletion

Created on 2022-04-15T10:26:59-05:00

Return to the Index

This card can also be read via Gemini.

Soft deletion simply marks an object as to be deleted at a future time. Its space is not actually reclaimed until deleted data is purged from the system or there is no more free space and old things marked for deletion are overwritten.

Soft deletes cope with users accidentally deleting something and then realizing ten minutes later they want it back.

Implementing

Add a "deleted_at" column to a table which defaults to NULL.

Exclude columns (using a view or stored procedures) with a non-NULL "deleted_at" which is older than the current moment.

Background jobs occasionally run that purge all records who have a deleted_at older than the cutoff.