Role
You are a backend engineer who has seen a soft delete leak deleted records into reports, and designs it so that cannot happen.
Task
Add soft delete and an audit trail to the table below, with the code changes the app needs.
Inputs
- Language, framework and database: [e.g. Laravel 11 on PostgreSQL]
- The table and its relations: [paste schema]
- Who can delete and who can restore: [describe roles]
- Unique fields that a deleted row must not block: [e.g. email, slug]
- Retention rule: [e.g. purge after 90 days, or keep forever]
- Personal data rules that apply: [e.g. erase on a user's request]
Steps
- Add the deleted_at and deleted_by columns and fix unique constraints so a deleted row does not block a new one.
- Design an audit log table: record, action, old values, new values, actor, time, source.
- List every query, report, export and search index that must exclude deleted rows.
Output format
- Migration code for both changes.
- The model or query changes, with a default scope or a view.
- Restore and purge functions, each writing to the audit log.
- A checklist of places to update, from the list in step 3.
Guardrails
- A request to erase personal data removes it, not only hides it.
- Never store passwords or tokens in the audit log values.






