Get the latest tech news

Avoiding the soft delete anti-pattern


24 Apr 2024 Programmers hate deleting things; we’ve all felt that feeling in the pit our stomach when we realise that thing we deleted was really deleted, and on the other hand the security of deleting some unused code, safe in the knowledge that it’s still really there in version control. In the sphere of databases, this terror of deleting things leads people to advocate soft deletion: instead of really deleting a record, you add a field which marks the record as deleted, and you treat any record marked in that way as if it were deleted.

You can no longer rely on SELECT s to only return live data; you have to remember to check the deletion marker in each WHERE clause (and in each JOIN; I nearly forgot about that while writing this, a reflection of the many times I’ve forgotten about it while implementing this). Of course, the extra complexity introduced by soft deletion isn’t necessarily a reason to avoid it; perhaps it’s a price worth paying in the noble quest to never lose data. Now, this rollback ability isn’t usually unlimited (and even if it is, it’s not an entirely trivial process), so after some point the data really will be lost, so this approach won’t work if you need to maintain a historical record for an extended period of time.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of pattern

pattern

Related news:

News photo

Show HN: Browser-based knitting (pattern) software

News photo

Adobe Unveils Dress That Can Change Its Pattern On the Fly