AI coding agents write application code and, often, the commands that change a database. The code can be reverted if it is only in git. The database command may already have run. This guide is about keeping production data out of that path.
It does not describe a tool that intercepts or reverses an agent. You will not get that from a checklist. You get it from credentials, a separate database, and a copy you have restored.
Give the agent a database you can lose
Create a development database with no production data, or with a sample you have reviewed. Point the agent’s environment at that database only. The production connection string stays in the production host and in a secrets store the coding session cannot read.
If you need realistic data, copy a subset into the development database. Strip passwords, tokens, and data you are not allowed to move. Do the copy with a role that can read production, then remove that role’s password from the coding environment. Encrypt the export in transit and at rest. Restrict who can read the file. Keep any copy you retain outside the production database, and decide how long you will keep it before you delete it.
A shared staging database is still a system other people depend on. Treat a destructive command there as a production command: reviewed, backed up, and run by a person.
Use a role that cannot do everything
The agent does not need a superuser, the Postgres postgres role, or a service-role key that bypasses application checks. Create a role for local development that can change the development schema and data and cannot connect to production.
On Supabase, row-level security is part of this picture for anything the API exposes. Supabase’s documentation says a table in an exposed schema without row-level security is readable and writable by any role with a grant on it. Enable row-level security on those tables. On projects that still grant anon and authenticated by default, Supabase says to revoke those grants, because adding policies does not remove them.
A grant change still has to leave the application’s legitimate access in place. Revoking anon or authenticated will break any query the application still runs as that role. Make the change in a development environment, exercise the paths real users rely on, and deploy it to production only after that check. Row-level security protects the API. It does not protect you from a session that has the database owner password. Credential separation still comes first.
Read every schema change
A migration file is a production change even when an agent wrote it in a branch. Before it runs anywhere but your disposable database, read it for:
DROP,TRUNCATE, andDELETEwithout a predicate.- Columns that become non-null without a backfill.
- Changes to grants, row-level security, or functions that run with elevated rights.
- Data rewrites that will lock a large table.
Apply it to the disposable database and look at the application, not only at a green migration command.
Take a restorable copy first
PostgreSQL documents three backup approaches: an SQL dump, a file-system-level copy, and continuous archiving with point-in-time recovery. They fail differently. A dump is a logical copy you can move. A file-system copy needs a consistent snapshot of the data directory. Continuous archiving can return you to a moment between dumps, if you have actually configured it and tested a recovery.
On Supabase, the hosted equivalent is documented as daily backups on paid plans and optional point-in-time recovery. Restoring from the dashboard takes the project offline, and restoring over the current project replaces its current state. Supabase says to restore to a new project if you need to keep that state. The details and the CLI dump commands are in How to Back Up Supabase Independently.
Take the copy before the migration, not after you notice the migration was wrong. If the only copy is the database you are about to alter, you do not have a copy. Encrypt the copy, restrict who can read it, keep the credential that created it separate from the file, and retain it independently of the database you are about to change.
Rehearse on a separate target
Restore the copy into a new database or a new project. Confirm a table you chose in advance. Confirm the application can read it with the role it will use in production, which may not be the role that took the dump. Custom role passwords are a common gap: Supabase documents that daily backups do not store them.
Write down the time the copy was taken and the time the restore finished. Those two times are the start of a recovery point and a recovery time. They are measurements from a drill, not targets you hope for. The next guide, backups versus verified recovery, is about how to record them without pretending a finished dump was a finished restore.
If a command already ran
Stop the agent. Do not run a second, improvised “undo” against production. If you have point-in-time recovery, choose a moment before the command and restore to a new project so you can compare. If you have a dump, restore that dump to a new database and see what it still contains. If you have neither, say so in the incident notes. Guessing that a host “probably has backups” is not a restore.