Group
  • Database

    Implement soft deletes without breaking queries

    Adds deleted_at handling with every query updated to respect it, plus a purge path for real deletion.

    • Improve quality
    • Plan & validate
    • Intermediate
    • General

Free Prompt

Implement soft deletes for the records in my app that users can delete but the business might need back: user-generated content, accounts, projects, orders where audit trails matter. Tell me first which models you're including and why. Implement: a deleted_at timestamp (nullable) on each included model; every query in the app updated to exclude soft-deleted records by default (this is the part everyone misses: list pages, counts, exports, admin views, uniqueness checks, and the 'load one record' path all need it); a deliberate way to include deleted records where they're legitimately needed (admin restore view); and a purge job or manual process that hard-deletes records after a retention window, since soft-deleted data kept forever is a privacy liability, not a feature. Update unique constraints to account for soft deletes (a deleted user's email shouldn't block a new signup with that email if that's the intended behavior; tell me which way you chose). Do not soft-delete records that are sensitive enough to require real deletion on request. Deliver: the model list, every query updated (show me the count before and after so we know none were missed), the purge plan, and verification: delete a record, confirm it vanishes from every list and count, restore it, and confirm the purge path actually removes it.

What This Does / How This Helps

Adds trash-can deletion: records disappear for users but stay recoverable, with every single query updated to respect the deleted flag and a purge path so data doesn't pile up forever. Soft deletes done halfway are worse than no soft deletes. The deleted post vanishes from the list page but still shows up in counts, search results, and the direct URL. The prompt's value is the completeness sweep: every query path audited, including the easy-to-forget ones like exports and uniqueness checks. The purge plan matters too: 'deleted' data you keep forever is still data you have to protect and disclose, so there's a real deletion path at the end of the retention window.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts