I have an application with a table named active_clients which has five columns, user_id, is_active, created_at, updated_at, and deleted_at.

I add and delete rows 1000s of times per day. But, what I discovered is when I used db.Delete(&ourRow) on a row - it wouldn't actually delete it. It would simple set the deleted_at column to the current time. The row itself would stick around causing our tables to explode in size throughout the course of a day (as I added/deleted many rows).

This is behavior that is outlined in the documentation here. When you use deleted_at, the Delete will be a soft delete. I'd like to keep this soft delete functionality in my application.

This brings me to my main question:

Whats the best way to use soft deletes and avoid the table exploding in size? My basic idea is to set up a job that will automatically delete columns set with a deleted_at column that is not null once every 30 minutes. Is this a solid approach or is there something more standard I can do?

0 Answers