wowprompt

Soft delete with an audit trail for records users can remove

Designs soft delete for a table, so removed records stay recoverable, together with an audit log of who changed what and when, the query changes that keep deleted rows out of normal views and a purge job for data that must really go. Use it when users delete things by mistake, or when a change history is needed for compliance.

Schema changes for soft delete and an audit log, the updated queries, a restore action, a purge job and a list of places that must filter deleted rows
The output this prompt produced, unedited.

The prompt

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

  1. Add the deleted_at and deleted_by columns and fix unique constraints so a deleted row does not block a new one.
  2. Design an audit log table: record, action, old values, new values, actor, time, source.
  3. List every query, report, export and search index that must exclude deleted rows.

Output format

  1. Migration code for both changes.
  2. The model or query changes, with a default scope or a view.
  3. Restore and purge functions, each writing to the audit log.
  4. 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.
soft deleteaudit trailaudit log tabledata recoverydeleted at columnchange history

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity