← All guides

AI Agent Deleted Your Database? How to Recover It and Prevent It

ClaudeReplitCursorSupabase

You asked an AI coding agent to fix a bug or tidy up a migration. A few minutes later your app shows empty pages, and the agent’s log has a DROP TABLE, a DELETE without a WHERE, or a “reset” of the database you didn’t ask for.

Take a breath. In many cases the data can be brought back, but what you do in the next hour matters. This guide walks through stopping further damage, finding out what backups you actually have, restoring without making things worse, and setting up guardrails so it doesn’t happen again.

This isn’t a rare, theoretical risk. In July 2025, SaaStr founder Jason Lemkin reported that Replit’s agent deleted his production database during a code freeze, then told him a rollback wasn’t possible. As The Register reported, the rollback did work. Replit later wrote that he was able to fully restore the database “so that no data was lost”, and that its agent now works on its own development database, kept apart from production (Replit blog).

Step 1: stop the damage

Before you try to restore anything:

  1. Stop the agent. End the session or cancel the running task. Don’t ask the same agent to “fix it” yet; it may run more destructive commands, and it may be wrong about what can be recovered, as in the case above.
  2. Take the agent’s credentials away. Remove the production connection string from the project’s .env file, or rotate the database password or key so the old one stops working. On Replit, if a production connection string was exposed, its docs explain how to regenerate production database credentials.
  3. Pause writes if you can. New sign-ups and orders written after the deletion complicate recovery. A maintenance page or pausing the app for a short time can help.
  4. Write down the time. Note, as precisely as you can, when the deletion happened. Point-in-time recovery works from timestamps, and you’ll want to restore to just before that moment.
  5. Save the agent’s log. The transcript tells you exactly which commands ran, against which database. Copy it somewhere safe.

Step 2: find out what backups you have

Recovery options depend entirely on where your database lives and which plan you’re on. Here’s what each vendor’s documentation says.

Supabase

From Supabase’s backups docs:

  • Pro, Team and Enterprise projects are backed up daily. Pro can access the last 7 days, Team 14 days and Enterprise up to 30 days, under Database → Backups in the dashboard.
  • Free plan projects aren’t covered by that daily backup schedule. Supabase recommends that free projects regularly export their data with the CLI’s db dump command and keep off-site backups. If you’re on the free plan and never exported, there may be no Supabase backup to restore.
  • Point-in-Time Recovery (PITR) is an add-on for Pro, Team and Enterprise projects. It lets you restore to a chosen moment “with up to seconds of granularity”, and requires at least a Small compute add-on. When PITR is on, daily backups stop because PITR replaces them.
  • Storage files aren’t included. Database backups only contain metadata about objects stored via the Storage API, so restoring won’t bring back deleted files.
  • Deleting a project is final. Supabase permanently removes its data and backups.

Neon

Neon calls its point-in-time recovery instant restore. According to Neon’s docs, you can restore a root branch to any moment within your project’s history window, using a timestamp or log sequence number. Before restoring, Time Travel Assist lets you run read-only queries against a past moment to find the right point.

How far back you can go depends on the history window, which defaults and caps by plan: Free is 6 hours (and capped at 1 GB of history), Launch defaults to 1 day with a maximum of 7, and Scale defaults to 1 day with a maximum of 30. If the deletion happened outside that window, instant restore can’t reach it.

Replit

Replit’s data recovery docs describe two databases with two recovery paths:

  • Development database: restore it with a checkpoint rollback, on all plans, with up to 7 days of history. By default rollbacks don’t touch your database; you have to select Database under Additional rollback options (Replit checkpoints and rollbacks).
  • Production database: point-in-time restore and optional scheduled daily backups. Core keeps up to 7 days of history; Pro and Enterprise up to 28 days, with 7 as the starting default.

Replit’s docs also say Agent can’t modify the production database; it works on the development database, and structural changes are applied to production when you publish (Replit development and production databases). If you removed a production database yourself, Replit describes a 7-day soft-delete period during which support can restore it. If the data only looks missing in the published app, check that it isn’t reading the other database first: Step 5 of Replit app not working covers that.

Anything else

If your database is somewhere else, look for its “backups” or “point-in-time recovery” page and check what your plan includes. Also check for your own copies: a recent pg_dump file, a CSV export, a staging database that was copied from production, or data in other systems (your payment provider, email tool or analytics) that could help you rebuild key records.

Step 3: restore without overwriting newer data

A restore usually replaces the current database with the old one. Anything written after the restore point, such as sign-ups since the deletion, is lost unless you save it first.

  • Supabase: restoring makes the project inaccessible during the process, and downtime grows with database size. On paid plans, Restore to a New Project creates a separate copy from a backup or a PITR timestamp, leaving your current project as it is (Supabase: Restore to a new project). That lets you copy the missing rows back into the live project instead of rolling everything back.
  • Neon: instant restore is “a complete overwrite”, not a merge, and applies to every database on the branch. Neon automatically keeps the branch’s pre-restore state as a backup branch named like {branch_name}_old_{head_timestamp}, so you can still reach data written after the restore point.
  • Replit: restoring the database doesn’t restore your code, and rolling back code doesn’t restore the database. To bring both back to the same moment, Replit says to restore the database, roll back to the matching checkpoint, then publish again. Restoring a scheduled backup “does not delete the current data”, according to its docs.

A careful order of operations:

  1. Take a fresh dump or copy of the database as it is now, even if it’s damaged.
  2. Restore to a separate copy where your platform allows it, and check the data there.
  3. Decide whether to switch over completely or copy only the missing tables or rows back.
  4. Re-test sign-in, payments and anything else that writes data before you reopen the app.

Step 4: recover deleted files (not data)

If the agent also deleted or rewrote code, that’s a separate problem with a separate fix. Git, editor history and agent checkpoints can bring back code, and our guide on undoing AI agent changes in Cursor and Windsurf with git walks through it. But git only tracks files in your repository. It won’t bring back rows that lived in a hosted database.

Step 5: understand why it happened

Patterns that can lead to incidents like this:

  • Production credentials on the developer’s machine. The agent reads .env, finds the production database URL, and runs commands against it, believing it’s a local or test database.
  • Destructive migrations. A “reset”, “push” or “drop and recreate” command meant for a local database is pointed at the real one.
  • Approval prompts turned off. Modes that run every command without asking remove the last moment where a human could say no.
  • Trusting instructions alone. Telling the agent “don’t touch production” in the prompt isn’t a control. Anthropic’s Claude Code docs are explicit: “Permission rules are enforced by Claude Code, not by the model”. Instructions in your prompt or CLAUDE.md don’t change what the tool allows (Claude Code permissions).

Step 6: guardrails so it can’t happen again

Keep production out of reach

  • Keep development and production data apart. Your agent should only ever see a development or staging database. Replit now does this by default; on Supabase or Neon, create a separate project or branch for development.
  • Don’t keep production credentials in local .env files. Put them only in your hosting provider’s environment settings.
  • Give tools the least access they need. In Postgres, the predefined pg_read_all_data role allows reading all tables without write rights, and it doesn’t bypass row-level security (PostgreSQL predefined roles). If an agent or script only needs to read, use a role like that rather than the owner account. Our guide to Supabase RLS policies explains how row-level security fits in.

Configure your agent’s permissions

Claude Code has allow, ask and deny rules. Deny rules are checked first, and a matching deny can’t be overridden by an allow rule. You can manage them with /permissions or in .claude/settings.json. Plan mode lets Claude explore without editing source files, and you can stop anyone using the skip-all-prompts mode by setting permissions.disableBypassPermissionsMode to "disable" in a settings file (Claude Code permissions).

Know the limits. Anthropic’s docs note that a deny rule like Bash(git push *) won’t match the same command written another way, and point to sandboxing or a PreToolUse hook when you need enforcement that doesn’t depend on the command text. That’s why credentials matter more than rules: an agent can’t drop a database it can’t connect to.

Cursor controls this with Run Modes under Settings → Agents → Approvals & Execution. Auto-review runs allowlisted calls, sandboxes shell commands when it can and sends the rest to a classifier; Allowlist only runs what you’ve approved; Run Everything runs every call with no prompts. You can add plain-English rules like “every database migration command should go through approval first” to a permissions.json file. Cursor’s own docs say “Auto-review is not a security boundary”, because the classifier can make mistakes (Cursor Run Modes).

Make backups boring

  • Check today which backups and PITR window your plan really includes, using the vendor pages above.
  • If you’re on a free tier, schedule your own regular exports, for example with supabase db dump (Supabase CLI reference), and store them somewhere other than the database provider.
  • Practise a restore into a separate project once. Finding out how it works during a calm afternoon beats learning it during an outage.

For a broader pre-launch list, see the AI app production readiness guide.

If your data is still missing, a vetted senior engineer can attempt recovery, lock production away from your agents and show you what went wrong. Fixed price, agreed upfront. See /fix/claude, /fix/replit and /fix/cursor.

FAQ

Can I recover a Supabase database without PITR?

On Pro, Team and Enterprise plans, yes, from the daily backups: 7, 14 or up to 30 days back depending on plan. You’ll lose changes since the last daily backup. On the free plan, Supabase’s docs don’t list daily backups, so recovery depends on exports you made yourself.

Does Replit keep database backups?

Yes. Development databases can be restored to an Agent checkpoint with up to 7 days of history on all plans. Production databases support point-in-time restore (up to 7 days on Core, up to 28 on Pro and Enterprise) and optional scheduled daily backups.

How do I stop Claude Code running destructive commands?

Add deny or ask rules for commands you never want run without you, keep the bypass mode disabled, and use plan mode for exploration. Most importantly, don’t give it production credentials. Anthropic’s docs note that pattern rules can miss a command written another way, so pair them with sandboxing or a hook if you need a firm limit.

Should agents ever have production credentials?

As a rule, no. Let agents work against a development database and apply changes to production through a reviewed migration or deploy step. If an agent truly needs to look at production data, give it a separate read-only role.

Will git bring back my data?

No. Git tracks the files in your repository, not rows in a hosted database. It can restore deleted code or migration files, but data has to come from a database backup, point-in-time recovery or your own exports.

Comments

Add a comment

Generated for you. Click to type your own.

Required. Never shown on the page. Privacy policy.

Basic markdown: **bold**, *italic*, `code`, lists, quotes, and fenced code blocks. HTML shows as plain text.

Your draft stays on this device until you post.