A user writes: "I deleted it by accident, can you get it back?" You open your host's backup page and find that a restore puts back the whole database, and wipes everything everyone else did since. Apps built with Lovable, Bolt, Cursor and Replit rarely have anything built for this request. Vendor facts below come from each vendor's own docs, checked in November 2026.
Short answer: Build three layers. First, soft delete: mark a row as deleted instead of removing it, so there is a trash and an undo. Second, a change history: a table that records who changed what, with the old and new values. Third, know what your host's backups can and cannot do, so you can use them as the last resort, not the first. Soft delete handles most "oops" cases in seconds. All of this keeps personal data, so purge it when a user leaves.
1. Why a backup restore is the wrong tool for one record
Backups are made for disasters, and work on the whole database. This is how each host's docs describe it.
Supabase
The Supabase backups page describes restoring "a project to any of the backups", and says "Restoring to an earlier point in time replaces the current database state." It also warns: "The project is inaccessible during this process, so plan for downtime beforehand." On plans: "We automatically back up all Pro, Team, and Enterprise Plan projects on a daily basis", and "Pro, Team and Enterprise Plan projects can enable PITR as an add-on." Pro projects get "the last 7 days of daily backups". The page does not describe restoring a single table or record.
Neon
Neon's instant restore page says "you can restore a root branch to an earlier state in its own or another root branch's history", and that it is "a complete overwrite of the database timeline, not a merge or refresh." A restore overwrites. But Neon's branches page also lists a "Past data" option that "Creates a copy using data from a specific past date and time of the parent branch." It adds: "You can only specify a date and time that falls within your history window." The Neon glossary calls the history window the setting that "controls how long Neon retains change history for your branches". So the safe way is a copy: create a branch from the time before the delete, find the lost rows there, and copy only those rows into your live branch. Neon's docs describe the branch. The copying step is my suggestion, and I did not find a Neon page that describes it.
Firebase and Firestore
Firestore's point-in-time recovery page says it "protects against accidental deletion or writes" and that "PITR data is retained for 7 days in the PITR window." For one lost document it describes a different route than a full restore: read the old version with a past timestamp, then "write the results back into the live database." That is the single-record fix, but PITR must be on before the mistake. Scheduled backups work on the whole database: "A restore operation writes the data from a backup to a new Cloud Firestore database", so you still copy the lost documents across yourself. Retention can be set "up to 14 weeks (14w)".
The pattern: a branch, a clone or a separate restored copy lets you take back only what was lost, if your host offers it. A restore in place does not. For general backup setup, read backups for Supabase, Neon and Firebase.
2. Layer one: soft delete
Instead of DELETE, add a deleted_at column. A row with a value there is "deleted". A row with null is live. Then:
- Every normal query gets
where deleted_at is null. Lists, counts, search and exports too. One missed query shows deleted rows again. - A Trash page shows rows where
deleted_atis not null, with a Restore button that sets it back to null. - A scheduled job removes rows that have been in the trash for, say, 30 days. See scheduled jobs on Netlify, Vercel and Supabase.
On Supabase, hide deleted rows in your Row Level Security policies too, not only in the app code. The Supabase RLS guide says "Each policy is attached to a table, and the policy is executed every time a table is accessed" and "You can specify select policies with the using clause." Put deleted_at is null in that clause. I did not find a built-in Supabase soft delete feature, so this is something you build.
The trap is unique values. If emails or slugs must be unique, a soft-deleted row still holds its value, and the user cannot sign up again with it. Use a partial index. The PostgreSQL docs say it can "enforce uniqueness among the rows that satisfy the index predicate, without constraining those that do not."
alter table notes add column deleted_at timestamptz;
create unique index notes_user_slug_live
on notes (user_id, slug) where deleted_at is null;
-- delete: update notes set deleted_at = now() where id = 42;
-- restore: update notes set deleted_at = null where id = 42;
On Firestore, the same idea is a deletedAt field. Filter on it in every query, and in your security rules if you want to block reads of trashed documents. Note what Firebase says in its rules and queries guide: "security rules are not filters". The query itself must be written so the rules can allow it.
3. Layer two: a change history
Soft delete covers deletes. It does not tell you that someone changed a price from 40 to 4, or who did it. For that, keep a history table filled by a database trigger. The PostgreSQL docs say "PL/pgSQL can be used to define trigger functions on data changes or database events", with OLD as the "old database row for UPDATE/DELETE operations" and NEW as the "new database row for INSERT/UPDATE operations".
create table notes_history (
id bigint generated always as identity primary key,
changed_at timestamptz not null default now(),
changed_by text default current_user,
action text not null,
old_row jsonb, new_row jsonb
);
create function log_notes_change() returns trigger
language plpgsql as $$
begin
insert into notes_history (action, old_row, new_row)
values (tg_op, to_jsonb(old), to_jsonb(new));
return coalesce(new, old);
end $$;
create trigger notes_audit after insert or update or delete
on notes for each row execute function log_notes_change();
Store who, when, which action, the old row and the new row as JSON. Note that current_user is the database role, not your app's user. To record the real person you must pass the user id into the trigger. I did not verify a method for this post, so check your platform's docs. To undo a bad edit, find the old row in old_row and write it back.
Supabase also has pgAudit. Its docs say it "can be used to selectively track activities within your database", but "By default, PGAudit records queries, but not the returned rows." So it logs who ran what, not the old values. For undo, a trigger table fits better.
On Firestore, use a Cloud Function. In the Firestore triggers docs, onDocumentWritten is "Triggered when onDocumentCreated, onDocumentUpdated or onDocumentDeleted is triggered", and you get "event.data.before" and "event.data.after" snapshots. Save both into a history collection.
4. Privacy: trash and history keep personal data
A soft-deleted row is not deleted. A history table holds old copies of every row. When a user deletes their account or asks you to erase their data, both must be cleared too. The GDPR text on EUR-Lex, Article 17(1), says "The data subject shall have the right to obtain from the controller the erasure of personal data concerning him or her", for example when "the personal data are no longer necessary in relation to the purposes for which they were collected or otherwise processed". Purge trash after a fixed number of days, give history a retention limit, and delete both for a user who leaves. See what to remove when a user deletes their account and the GDPR checklist for a small app.
5. What to do today if data is already gone
- Stop writes to the affected table if you can. New changes can overwrite what you want to recover, and time is running against the retention window.
- Check your host's restore options and their time window now. Supabase daily backups, Neon's history window and Firestore's 7 day PITR window all expire.
- If your host offers a branch, clone or copy from a past time, restore into that, not into the live database.
- Find the missing rows in the copy and copy back only those rows.
- If there is no such option, contact the host's support before you do a full restore.
Prompts for Lovable, Bolt and Cursor
- "On the table projects, replace DELETE with soft delete: add a deleted_at timestamptz column, set it instead of deleting, and add a Trash page with a Restore button. Update every query, view and Row Level Security policy so rows with deleted_at set are hidden everywhere else. Show me the list of places you changed."
- "Add a projects_history table and a Postgres trigger that stores the action, the time, the old row and the new row as jsonb on every insert, update and delete. Do not let the app's normal users read or edit this table."
- "Add a scheduled job that permanently deletes rows with deleted_at older than 30 days, and history rows older than 180 days. Run it daily and log how many rows it removed."
Checklist
- Deletes set
deleted_atinstead of removing rows. - Every list, count, search and policy hides deleted rows.
- A Trash page with Restore exists, and you tried it.
- Unique values use a partial index, so a user can sign up again.
- A history table and trigger record who, when, old and new values.
- Trash and history are purged on a schedule and when a user leaves.
- You know your host's restore options and their time window.
Before you change a live table, read how to change your database without losing data. Also check who can touch data at all: admin pages, roles and IDOR.
Want this fixed for you?
I finish and fix apps built with Lovable, Bolt, Cursor or Replit, including adding a trash, a change history and a safe restore plan. Or send me the details and I'll reply within 24 hours.