Menu

Thinking of adding soft delete (deleted_at)? Decide these 5 things first

#database#redditdatabase#deleted#soft#unique
Reading 0:00
15s threshold
  1. Unique constraints. A deleted user still "uses" their username. Use a partial unique index (`where deleted_at is null`).
  2. Every query must filter deleted rows. Miss one, and deleted data shows up in a report or API response.
  3. Foreign keys. What happens to orders that belong to a soft-deleted customer?
  4. Real deletion. Privacy laws may require you to actually erase data, so soft delete can't be the only option.
  5. Restoring. What if the username was taken again while the old account was deleted?

Do you use soft delete, or did you move to archive tables instead?

submitted by /u/ig_suyas
[link] [comments]