top | item 39941342

(no title)

LogicalBorg | 1 year ago

> To prevent deleting data by mistake, we invent soft-delete pattern by having a is_deleted column. However, this brings extra complexities around foreign key, unique index enforcement. Ideally, PostgreSQL could allow users to configure an archived table. The removed data is moved to the archived table first and purged after a configured retention period. This simplifies application logic and data compliance work.

You can get the same result by changing your is_deleted boolean field to a date_deleted date field. Then use a cron to purge all the records with dates older than the configured retention period.

discuss

order

locopati|1 year ago

if you're using an ORM that has an updated_at field, you can keep the boolean and rely on the updated date.