How to Configure Mastra Supabase Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a mastra supabase prevent delete workflow, give your agent a custom database role without delete rights. You can also set row rules that block row removal during agent runs. Many teams start by giving their AI agents the default admin login to move fast. Broad permissions let a bad prompt wipe out whole tables by mistake. How a mastra supabase prevent delete setup works Every new Supabase project comes with a default postgres role that holds admin rights. Supabase does not give out

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To set up a mastra supabase prevent delete workflow, give your agent a custom database role without delete rights. You can also set row rules that block row removal during agent runs. Many teams start by giving their AI agents the default admin login to move fast. Broad permissions let a bad prompt wipe out whole tables by mistake.

How a mastra supabase prevent delete setup works

Every new Supabase project comes with a default postgres role that holds admin rights. Supabase does not give out full superuser rights because those allow destructive actions. Instead, the default postgres role gets extra rights for common admin tasks. Queries that you run in the project dashboard use this default postgres role. When you set up your project, you create the password for this admin role.

Supabase says you should never share this main password with an external service. Instead, you should make a separate database user for every service or agent. Supabase also creates built-in roles like the anon role for public requests. For a Mastra agent, a dedicated role lets you pick exact table rights. You can grant read, insert, and update rights on specific tables while withholding delete rights. If the agent tries to remove rows, the database rejects the query right away. You can also turn on row rules to control which rows the role can change.

What native roles solve and what they miss

Custom database roles stop your agent from running direct delete statements on protected tables. They also stop the agent from dropping tables or changing your database structure. This setup works well when an agent only needs to read or add records.

Still, database roles only check who logs in at the start of a session. They cannot inspect what individual statements do while they run in flight. For example, an agent with update rights can still overwrite columns with blank values. That kind of bad update destroys data just like a delete query does. A static role also cannot tell if a human approved a risky action first. If a task ever needs one safe delete, you must change role grants by hand. Static grants also do not mask sensitive fields like emails or phone numbers in results.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why runtime query checks matter for AI agents

AI agents build and run queries based on user input and model outputs. Because model outputs can change on every run, static roles leave gaps in daily operations. Teams often end up maintaining many small roles for different agent tasks. Each new agent tool needs its own credentials and its own set of table rules. Over time, tracking which agent holds which key becomes hard for the team. When an error happens, database logs only show the shared role name, not the trigger. Teams need a way to inspect each query and mask card numbers or national IDs.

Add query and result controls beside Postgres

Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.

When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.

Frequently asked questions

Should I give my Mastra agent the default postgres role password?

No, Supabase recommends that you never share the default postgres password with other services. You should create a dedicated database user for your agent with limited table rights.

Does the default Supabase postgres role have full superuser access?

No, the default postgres role has admin rights, not full superuser rights. Supabase blocks superuser access to prevent destructive actions, though it grants extra rights for normal tasks.

Can a custom role without delete rights still ruin table data?

Yes, if the role has update rights, a bad query can overwrite existing values. Native roles allow or block command types, but they do not check query details in flight.

The query runs. The emails stay hidden.