How to Configure Mastra CockroachDB Prevent Delete
To set up a mastra cockroachdb prevent delete rule, restrict the database role permissions. You also need to limit the custom tools your AI agent can run. Many engineering teams start by giving their agent a default database user. That default user often has full write and delete powers across all tables. When an AI agent has broad rights, one bad prompt can wipe out production rows. A safe setup strips away drop and delete rights before the agent runs a query. How to set up a mastra cockroach
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 cockroachdb prevent delete rule, restrict the database role permissions. You also need to limit the custom tools your AI agent can run. Many engineering teams start by giving their agent a default database user. That default user often has full write and delete powers across all tables. When an AI agent has broad rights, one bad prompt can wipe out production rows. A safe setup strips away drop and delete rights before the agent runs a query.
How to set up a mastra cockroachdb prevent delete workflow
A strong setup starts inside the database itself. CockroachDB manages table rights through role-based rules. Admins create a dedicated user role just for the Mastra agent. They grant this role select, insert, and update rights on specific tables. They leave out the delete and drop privileges during this step.
Next, the team shapes how the Mastra app talks to the database. Mastra agents use typed tools to run actions against outside data stores. Instead of giving the agent a raw query tool, developers build narrow tools. One tool might fetch user status, while another tool inserts a new log row. Neither tool contains logic that removes records.
Teams also use soft deletes in their schema design. They add a status column or a timestamp column to mark old records. When the agent needs to remove an item, it runs an update query instead. The row stays safe in the table, and the app hides it from normal views.
What native roles solve and what they leave open
Native database roles and narrow agent tools stop basic accidents. If an agent tries to run a delete statement, CockroachDB blocks the action right away. The database checks the role rights and returns a permission error. This approach protects your tables from simple mistakes and bad tool calls.
Still, static database roles only check who logs in at the start. They do not inspect what individual statements do while they run in flight. An agent with update rights can still overwrite critical data with blank values. A faulty update query without a filter clause can ruin an entire table at once. Static roles cannot tell the difference between a safe one-row update and a bulk overwrite.
End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Also, managing dozens of tiny database roles for different agents adds heavy toil. Developers often share one database login across many workflows to save time. When teams share logins, they lose track of which user or agent changed a row. They also lack built-in data masking for sensitive fields like emails or phone numbers. Raw card numbers and national IDs flow straight into the agent context unless rewritten in results.
Why runtime query checks matter for AI agents
AI agents build and run requests based on changing user inputs. Because prompts change every time, static login rules are not enough on their own. Teams need a way to check each query right before the database runs it.
Checking queries in flight lets teams block risky updates as well as deletes. It also helps teams log every action back to a specific agent task. When you combine strict database roles with runtime checks, your data stays safe from harm.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.
Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Can a Mastra agent still remove data if delete rights are off?
No, the database will reject any delete statement if the role lacks delete rights. Still, an agent with update rights could still overwrite fields with empty values. You should limit update rights to specific columns to lower this risk.
How do soft deletes help protect CockroachDB tables?
Soft deletes replace destructive delete commands with safe update statements. You add a flag column to mark rows as inactive instead of erasing them. If an agent marks the wrong row, your team can restore it in seconds.
Should my Mastra app share a database login with other services?
No, sharing a login makes it hard to track which app ran a bad query. Give your Mastra app its own database role with the lowest possible permissions. This setup keeps your audit logs clean and limits the blast radius of mistakes.
Related guides
In this post