Home › All prompts › Don't Let the AI Delete Your Data: Safe Database Changes

Mini pack

Free

Don't Let the AI Delete Your Data: Safe Database Changes

AI coding tools can run migrations, reset tables and delete rows faster than you can read what they're doing. These 9 free prompts help you see what a database change will touch before it runs, make it undoable, try it on a copy first, lock down deletes, and know what to do if data has already gone missing.

See what a database change will touch before the AI runs it, make it undoable, try it on a copy first, lock down deletes, and know how to recover if data goes missing.

9 prompts in 4 sections. Replace everything in [BRACKETS IN CAPS], then copy and paste into your AI tool.

Download the free PDF

PDF, 16 pages

Written for use with

  • Claude Code, Cursor's Agent or Codex: all 9 prompts are written for a coding tool opened in your project. Prompt 1.1 can also be used in an app builder's chat, as long as it shows you the change before it runs it, and Prompt 4.1 can be pasted into any AI chat. Prompts 1.2, 4.2 and 4.3 only read and report; 1.1, 2.1, 3.1, 3.2 and 4.1 wait for your OK or run nothing; 2.2 runs a change only on a test copy you confirm.
  • Any database: the steps aren't tied to one database or host. Where backups, copies or read-only logins depend on your host, the prompts point readers to their host's docs instead of making claims about any plan.
  • Claude Code and Cursor checkpoints: "snapshots of your files, not your database" was checked against Anthropic's Claude Code docs (Checkpointing) and Cursor's Agent docs (Checkpoints). The tip pointing to Claude Code Guardrails Prompt 2.2 links to the live pack.
  • SQL: DELETE with no WHERE removing every row, TRUNCATE and DROP were checked against the PostgreSQL docs; SQLite read-only mode against the SQLite docs.
  • No stats or X claims: the pack quotes no survey numbers or posts and makes no claims about any database host.

Written for use with Claude Code, Cursor's Agent or Codex. Not yet tested against them.

All 9 prompts

  1. 1.1 Tell Me What This Change Will Do to My Data First
  2. 1.2 Which Database Is the AI Connected To Right Now?
  3. 2.1 Write It as a Migration I Can Read and Undo
  4. 2.2 Try It on a Copy First and Show Me Before and After
  5. 3.1 Add "Never Delete Without Asking" Rules to My Rules File
  6. 3.2 Give the AI a Read-Only Login to My Database
  7. 4.1 Make Sure I Can Get My Data Back Today
  8. 4.2 Something Just Got Deleted: Stop, Look, Recover
  9. 4.3 What Did the AI Do to My Database in This Session?

Section 1: Know What Will Change Before Anything Runs

1.1 Tell Me What This Change Will Do to My Data First

Untested: not yet run against a model.

Use this when you're about to ask the AI for anything that touches your database, like a new field, a fix or a cleanup. It's for a plain list of every table, column and row the change would add, change or delete, before anything runs.

Use in: your coding tool (Claude Code, Cursor's Agent or Codex) opened in your project, or an app builder's chat.

Fill in: [WHAT I WANT TO CHANGE] (e.g. "add a phone number to user profiles").

I want to make a change that touches my database. Don't run anything yet. Don't edit, migrate, delete or reset anything until I say OK.

What I want to change: [WHAT I WANT TO CHANGE]

1. Tell me which database this change would run against: its name, the host it lives on, and whether it looks like the live one my users use or a test one. Don't show me any passwords or connection strings. If you can't tell, write "Check this".
2. List every table, column and row this change would add, change or delete. For each one, say in plain words what happens to the data already in it.
3. Mark anything that removes or overwrites data as DESTRUCTIVE in capital letters. That includes dropping or renaming a table or column, changing a column's type, deleting or updating many rows, and anything that resets or reseeds the database.
4. For each DESTRUCTIVE item, tell me a safer way to get the same result, if there is one.
5. Tell me how to undo this change, and whether undoing it would bring back the data or only the structure.
6. Show me the exact code or commands you'd run. Then stop and wait for my OK.

Tips to customize: Renaming a column can look harmless, but if the change is written as "drop the old column and add a new one," everything in that column is gone. Step 3 makes the AI say which way it's doing it, out loud. If the answer to step 5 is "the structure comes back but the data doesn't," that's your cue to use Prompt 4.1 first. Paste this before every database change until it's a habit, then keep it for anything marked DESTRUCTIVE.

1.2 Which Database Is the AI Connected To Right Now?

Untested: not yet run against a model.

Use this when you're not sure whether your coding tool, your local app or your scripts are pointed at your live database or a test one. It's for finding out, without changing anything, so the AI never tests a change on your real users by accident.

Use in: your coding tool (Claude Code, Cursor's Agent or Codex) opened in your project.

Fill in: [WHERE MY LIVE APP RUNS] (e.g. "Vercel", "Netlify", or "not sure").

I need to know which database my project talks to in each place it runs. This is read-only: don't connect to any database, run any query, or edit any file.

Where my live app runs: [WHERE MY LIVE APP RUNS]

1. Find every place my project reads its database settings from, like .env files, config files, scripts in package.json and any database tool's config. List each file by name.
2. For each one, tell me which database it points to (just the host name and database name) and whether it looks live or test. Never show me passwords, keys or full connection strings.
3. Tell me which settings my local app uses when I run it on my computer, and which ones you would use if I asked you to run a migration or a script right now.
4. If my local setup points at the same database as my live app, say so clearly at the top of your answer.
5. List any scripts or commands in this project that reset, reseed, wipe or drop the database, and which database each would hit.
6. Suggest the simplest way to give my local work its own test database, so my live data is never touched by testing. Don't set it up yet.

Tips to customize: Step 4 is the one that matters most. Plenty of beginner projects use the live database for everything, so any test, seed script or "let me reset that" from the AI hits real users. If that's you, a separate test database is the single biggest safety step in this pack. Keep the test database's details in a separate file from the live one, and make sure files like .env are listed in .gitignore.

Section 2: Make Changes You Can Undo

2.1 Write It as a Migration I Can Read and Undo

Untested: not yet run against a model.

Use this when the AI wants to change your database by running a command directly, or by editing the database through a dashboard. It's for turning the change into a migration file, a saved script that makes the change, with a matching script that undoes it.

Use in: your coding tool (Claude Code, Cursor's Agent or Codex) opened in your project.

Fill in: [THE CHANGE] (e.g. "add a 'status' column to the orders table"), [MY DATABASE TOOL] (e.g. "Prisma", "Drizzle", my host's migration tool, or "not sure").

Don't run anything on my database. Instead, write this change as a migration file I can read, save in git and undo.

The change: [THE CHANGE]
My database tool: [MY DATABASE TOOL]

1. Look at how this project already handles database changes, and use the same tool and folder. If there's no migration setup yet, tell me the simplest option for my stack and wait for my OK before adding it.
2. Write the migration so it keeps existing data. Add new things rather than deleting old ones where you can. If a step must remove or overwrite data, mark it DESTRUCTIVE and explain why it's needed.
3. Write the matching undo step (sometimes called a "down" migration or a rollback), and tell me in plain words whether undoing it brings back the data or only the structure.
4. Never change or delete an old migration file that has already run. Make a new one instead.
5. Explain each line of the migration in one plain sentence.
6. Tell me the exact command to run it on a test database first, and the separate command to run it on the live one. Don't run either.

Tips to customize: Rule 4 matters more than it looks. Editing a migration that has already run can make your test and live databases quietly disagree about what they look like. If the AI says your tool can't write an undo step, ask it, "What would I do by hand to reverse this?" and save the answer next to the migration. Commit the migration file in git before you run it, so you have a record of exactly what changed.

2.2 Try It on a Copy First and Show Me Before and After

Untested: not yet run against a model.

Use this when you have a change ready and want to see what it really does before it reaches your users. It's for running it on a test copy of your database and comparing the data before and after.

Use in: your coding tool (Claude Code, Cursor's Agent or Codex) opened in your project.

Fill in: [THE CHANGE OR MIGRATION FILE] (e.g. "the migration you just wrote"), [MY DATABASE AND HOST] (e.g. "hosted Postgres", "a SQLite file", or "not sure").

I want to test this change on a copy of my database before it touches my live data.

The change: [THE CHANGE OR MIGRATION FILE]
My database and host: [MY DATABASE AND HOST]

1. Tell me the safest way to get a test copy for my setup. That could be a separate test database, a copy or branch made by my host, or my local database with realistic fake data. Point me to the part of my host's docs that explains it, and say "Check this" if you're not sure my host offers it.
2. Wait for me to set up the copy and tell you it's ready. Confirm it's the copy, not my live database, before you run anything.
3. Before the change, count the rows in every table the change touches, and save a few example rows.
4. Run the change on the copy only.
5. After the change, count the rows again and show the same example rows. Show me before and after side by side.
6. Tell me anything that disappeared, changed in a way I didn't ask for, or failed. Then run the undo step and check that the copy is back to how it was.

Tips to customize: The row counts are your quickest alarm. If a table had 1,200 rows before and 0 after, stop there. If your test copy has only a handful of fake rows, add some messy ones too, like blank fields, very long names and old accounts, because real data is messier than test data. Only run the change on your live database once the before and after look right and the undo worked.

Section 3: Rules the Agent Can't Skip

3.1 Add "Never Delete Without Asking" Rules to My Rules File

Untested: not yet run against a model.

Use this when you want the agent to stop and ask every time it's about to run something that could wipe data. It's for adding clear database rules to the instructions file your coding tool reads at the start of every session.

Use in: your coding tool (Claude Code, Cursor's Agent or Codex) opened in your project.

Fill in: [MY RULES FILE] (e.g. "CLAUDE.md", "AGENTS.md", or "not sure"), [MY LIVE DATABASE'S NAME] (e.g. "the production database my live app uses").

Add a short "Database safety" section to my project's rules file, so you and any other AI tool follow it every session.

My rules file: [MY RULES FILE]
My live database: [MY LIVE DATABASE'S NAME]

1. If you're not sure which rules file this tool reads, tell me and write "Check this". Don't create a new one until I say OK.
2. Write these rules in plain, short lines:
   - Never run DROP or TRUNCATE, or a DELETE or UPDATE without a WHERE clause, on any database without showing me the command and getting my OK first.
   - Never reset, reseed or wipe a database, and never run "migrate reset" or similar commands, without my OK.
   - Never connect to or run anything on [MY LIVE DATABASE'S NAME] unless I ask in that message. Use the test database for everything else.
   - Make every structure change as a migration file. Never edit an old migration that has already run.
   - Before any change that touches data, list what it will add, change or delete, and wait for my OK.
   - If a command fails, stop and tell me. Don't try a more forceful version.
3. Keep the section under 15 lines. Show me the exact text and where it goes, then wait for my OK before saving it.

Tips to customize: The last rule is there for a reason. When a migration fails, an agent may try to "fix" it by resetting or dropping something, and that's often how data goes missing. A rules file is guidance the AI reads, not a lock, so it can still slip, especially in a long session. That's why Prompt 3.2 takes away the power to delete altogether. If you use Claude Code, Claude Code Guardrails Prompt 2.2 adds permission rules that make risky commands ask first, which is a firmer block than a rules file.

3.2 Give the AI a Read-Only Login to My Database

Untested: not yet run against a model.

Use this when you want the AI to look at your data to debug something, but not be able to change or delete it. It's for setting up a separate database login that can only read, and using that one whenever the AI works with your live data.

Use in: your coding tool (Claude Code, Cursor's Agent or Codex) opened in your project.

Fill in: [MY DATABASE AND HOST] (e.g. "hosted Postgres", "MySQL", or "not sure"), [TABLES THE AI MAY READ] (e.g. "all tables", or "orders and products, but not users").

I want a separate database login for AI work that can read data but can't change or delete anything. Don't create it or run anything yet. Explain the steps first.

My database and host: [MY DATABASE AND HOST]
Tables the AI may read: [TABLES THE AI MAY READ]

1. Explain in plain words what a read-only login (sometimes called a role or user) is, and why it stops the AI from deleting data even if it tries.
2. Write the exact commands to create this login for my database, allowing reading only on the tables I listed. Explain each line. Point me to the part of my database's or host's docs that covers it, and say "Check this" if my host does it differently, for example through its dashboard.
3. Tell me how to keep this login's details in a separate setting from my app's main login, so I can choose which one an AI session uses.
4. Tell me how to test that it really can't change anything, using a harmless test on a table that doesn't matter.
5. Don't run any of this. I'll run it myself, or tell you to, once I've read it.

Tips to customize: A read-only login is the strongest guardrail in this pack, because it doesn't depend on the AI remembering anything. Even a delete that slips past every rule gets refused by the database itself. Keep your app's main login out of the AI's reach, and only switch to it for a change you've already checked with Prompts 1.1 and 2.2. Some hosted databases call this a "role" and set it up in their dashboard, so follow your host's docs if they differ from the AI's commands. If your app uses a SQLite file, there are no logins to set up, so ask the AI how to open the file in read-only mode instead.

Section 4: Before and After a Risky Change

4.1 Make Sure I Can Get My Data Back Today

Untested: not yet run against a model.

Use in: your coding tool (Claude Code, Cursor's Agent or Codex) opened in your project, or any AI chat.

Fill in: [MY DATABASE AND HOST] (e.g. "hosted Postgres", "a SQLite file", or "not sure"), [THE CHANGE I'M ABOUT TO MAKE] (e.g. "deleting old test accounts").

I'm about to make a risky change to my database, and I want to be sure I could get my data back if it goes wrong. Don't run anything on my database.

My database and host: [MY DATABASE AND HOST]
The change I'm about to make: [THE CHANGE I'M ABOUT TO MAKE]

1. Tell me what kinds of backups my host may offer, like automatic daily backups or restoring to an exact moment (often called point-in-time restore), and point me to the page in my host's docs and dashboard where I can see what's turned on for my project and plan. Don't guess what my plan includes; write "Check this".
2. Give me a short checklist to confirm, in the dashboard, that a backup from today or yesterday exists.
3. Tell me how to make my own extra copy right now, just of the tables this change touches, and where to keep it safe. Never put it in my git repository.
4. Write the restore steps in plain words, numbered, so I could follow them while stressed.
5. Tell me how long a restore might take and what my users would see during it, if you can tell. If you can't, say "Check this".

Tips to customize: A backup you've never restored is a hope, not a plan. If you have time, restore your extra copy into a test database once and check the rows are there. Some hosts only include backups on certain plans, so look at your own dashboard rather than trusting what the AI remembers. If step 2 finds no recent backup, make your own copy in step 3 before you go any further.

4.2 Something Just Got Deleted: Stop, Look, Recover

Untested: not yet run against a model.

Use this when data is already missing, and you think the AI (or a script it ran) deleted or overwrote it. It's for stopping more damage, working out exactly what's gone, and planning the recovery calmly.

Use in: your coding tool (Claude Code, Cursor's Agent or Codex), opened in your project. If it's the same session that made the change, paste it there, since it remembers what it ran.

Fill in: [WHAT'S MISSING] (e.g. "all the orders from this week"), [WHEN I NOTICED] (e.g. "about 10 minutes ago"), [MY DATABASE AND HOST] (e.g. "hosted Postgres", "a SQLite file", or "not sure").

Data is missing from my database and I think it was deleted or overwritten. Stop all other work. Don't run any more changes, migrations, resets or "fixes" on any database. From now on, only read and tell me.

What's missing: [WHAT'S MISSING]
When I noticed: [WHEN I NOTICED]
My database and host: [MY DATABASE AND HOST]

1. If you ran anything on a database in this session, list every command, in order, with the time if you know it and which database it hit. Mark any that removed or overwrote data. Don't leave any out.
2. Tell me what you think is gone, which tables, and roughly how many rows, and how sure you are. Write "Check this" where you're guessing.
3. Tell me what I should do in the next few minutes to stop it getting worse, like pausing a script that's still running or turning off a scheduled job. Don't do it yourself; tell me.
4. List my recovery options, most complete first: restoring to a moment just before the change (if my host offers it), a recent backup, my own copies, or rebuilding from other records like payment receipts or emails. For each, say what would be lost and point me to my host's docs.
5. Warn me about anything that could make recovery harder, like restoring over newer data that users added since.
6. Help me write a short, honest note to affected users, only if I ask for it.

Tips to customize: Move fast but don't rush the restore. Many hosts can restore to an exact moment only for a limited time window, so check your host's docs and dashboard straight away. Restoring the whole database can wipe out anything users added after the deletion, so ask the AI whether you can restore to a test copy first and move back only the missing rows. Checkpoints in Claude Code and Cursor are snapshots of your files, not your database, so a checkpoint won't bring back deleted rows. Once things are stable, run Prompt 3.1 so the same command can't run again without your OK.

4.3 What Did the AI Do to My Database in This Session?

Untested: not yet run against a model.

Use in: the same coding tool session (Claude Code, Cursor's Agent or Codex) you want to review.

Fill in: [WHAT I ASKED FOR IN THIS SESSION] (e.g. "fix the signup bug and add a 'last seen' field").

Before I finish, give me a plain record of everything you did to any database in this session. This is read-only: don't run, change or undo anything.

What I asked for in this session: [WHAT I ASKED FOR IN THIS SESSION]

1. List every command, query, script or migration you ran that touched a database, in order. For each, say which database it hit (test or live, by name only, no passwords) and what it changed.
2. Mark anything that added, changed or deleted data or structure, and anything that ran on the live database.
3. List any database changes you made that I didn't ask for, and why you made them.
4. List any new or changed migration files, and whether each one has run yet, and where.
5. Tell me anything I should undo, double-check or run on the live database myself, in plain numbered steps.
6. If you're not sure whether something ran, write "Check this" instead of guessing.

Tips to customize: An AI's memory of its own session can have gaps, especially in a long chat, so compare step 1 with your migration folder and git history. If step 3 isn't empty, ask why and decide whether to keep each change before you push. Running this at the end of every session that touched data takes a minute and catches most surprises while they're still small.

Get new free packs in your inbox

Optional. Every prompt here is free, and you don't need to sign up to use any of them. We email when we add new free packs. Unsubscribe anytime.

More free packs: Vibe Code Starter Pack Ship It Safe Fix My Bugs Ship It Live Make It Pretty Get Paid Signup Emails That Actually Arrive Lovable Credit Saver One Rules File for Every AI Tool Make Your Claude Code Limit Last Graduate From Lovable First App Store Submission Survive Your First Traffic Spike Get Found on Google First 100 Users Two AIs, One Project It Broke in Production Hit the Slop Wall? Refactor Without Breaking Everything Vibe Code From Your Phone AI Reverse Engineering Run Several AI Agents at Once Claude Code Guardrails Let AI Review Your AI's Code Make Your Cursor Usage Last Privacy Policy and Terms That Match Your App Install Skills, Plugins and MCP Servers Without Getting Burned Say What You Mean Prompt Injection: Don't Let a Web Page or a Strange File Hijack Your Agent Hit Your Limit Mid-Task? Switch AI Tools Without Losing Your Place Make the AI Teach You While It Builds Bolt Token Saver v0 to Production Claude Code Subagents and Skills for Beginners Logins, Tokens and JWTs in Plain English Put Your Web App on Their Phone Add AI Features in Lovable Is Anyone Using It? Simple Analytics for Vibe Coders Use the Cheap Model for the Easy Stuff: Claude Code Model Mixing Ship Updates Without Breaking the Live App: Preview Links, Checks and One-Click Rollback Try to Break It: Stress-Test Your App Before Strangers Do Claude Code Memory: Stop It Forgetting Your Decisions Fix Your Lovable Security Warnings Without Breaking the Live App What Will My App Cost to Run? A Monthly Bill You Can Predict Leave Claude Code Running Without It Getting Stuck Put Your Lovable App on Autopilot: Automations That Check and Report for You Spec and Tests First: Tell the Agent When It's Done Only Change What I Asked: Stop the AI Rewriting Code You Didn't Mention Stop Getting 429'd: Call Other People's APIs Without Hitting Limits Use the Current Version: Stop the AI Writing Outdated Library Code What Did My Agent Actually Do? Read Your Claude Code Session History Your First Google Play Launch: Get Through the 12-Tester, 14-Day Closed Test Will Anyone Want It? Check Your App Idea Before You Build Claude Code Code Mode: Try It Without Breaking Your Safety Checks Coding With Gemini 4 Neon: Make It Double-Check Its Own Work Understand the App You Already Built: A Guided Tour of Your Own Code Your Guess Might Be Wrong: Make the AI Find the Real Cause Before It Fixes Replit Missions: Give Agents a Goal, a Budget and Approval Rules Make Your Antigravity Quota Last: Pick the Right Gemini Model and Check /usage Turn a Claude Artifact Into a Desktop App, Without Giving It Too Much Access Built It for Work? Make Sure Only Your Team Can Open It Plan Before It Builds: Use GitHub Spec Kit So the Agent Builds the Right Thing Saves That Stick: Fix Data That Disappears Rebuilt Your Site With AI? Make Sure Google Can Still See Every Page Subscriptions and Paywalls: Gate Features by Plan Your AI App Builder Is Shutting Down: Get Your Code, Data and Domain Out Your Own Android App From a Prompt: Build It in Google AI Studio and Put It on Your Phone Backups You Can Actually Restore: Check, Copy and Test Your Supabase Data Accessibility Pass Before You Ship: Make Your App Work With a Keyboard, a Screen Reader and Zoom Update Your Dependencies Without Breaking the App: npm Updates, Audits, Major Upgrades and Dependabot