Skip to content

Letting an AI agent run SQL you can roll back

Giving an AI agent SQL access to a real database feels like handing over the keys. One wrong WHERE clause and a few thousand rows are different. Here is what Backa does when an agent runs SQL against Supabase, what can be rolled back, and what can't.

SystemsBacka··4 min read
LinkedIn X Email Markdown
update ordersset status = 'refunded'idstatus1041refunded1042refunded1043refunded1044refundedidstatus1041paid1042shipped1043paid1044pendingbeforeroll back

The short answer

  • ReadSELECT queries, tables, logs, advisorsNothing to roll back
  • Change rowsINSERT, UPDATE and DELETE through SQLRows rolled back
  • Deploy an Edge FunctionNew or replaced codeOld version back
  • Create a branch or project, pause a projectThe project-level switchesReversed
  • Change the schemaMigrations, DROP, ALTER, TRUNCATE, merging a branchLogged, can't be rolled back

When an agent changes rows

Before an agent's INSERT, UPDATE or DELETE runs, Backa reads the rows it is about to touch and keeps a copy. Then the statement runs as the agent wrote it.

Rollback puts those rows back the way the copy says, all in one transaction. Rows the agent inserted are removed, rows it changed get their old values, and rows it deleted come back. Either all of it goes back, or nothing does.

This works on tables that have a primary key, which is how Backa knows which row is which. Rollback for SQL is open for 7 days.

When someone else got there first

A database doesn't stand still. Between the agent's change and your rollback, your app may have written to the same rows. Before it puts anything back, Backa compares the rows with how the agent left them. If any of them have changed since, rollback stops and tells you, instead of overwriting newer data.

What no rollback can reach

Schema changes are a different kind of change. A dropped column takes its data with it, and there is no copy small enough to keep of a whole table. So migrations, DROP, ALTER, TRUNCATE and branch merges are written to the audit log, so you can see exactly what ran and when, but they can't be rolled back.

insert · update · deleteput backdrop · alter · truncatelogged only

Two more edges. Changes that database triggers make in other tables are not rolled back, only the rows the agent's statement touched. And SQL run from a saved notebook is not covered; the same SQL run directly gets rollback.

If an agent needs to change the schema, the safer road is a Supabase branch: try the migration there, look at it, and merge it yourself.

Edge Functions and projects

When an agent deploys an Edge Function, Backa keeps the files and settings of the version that was running. Rollback redeploys them as a new version, or deletes a function the agent created. Requests that came in between ran the agent's code.

A branch or project the agent created can be deleted again, and a paused project can be restored. Keep in mind that both cost money while they exist.