12-database-sql

12-database-sql is a cursor rule for Cursor from bybren-llc/a-safe-pulse. It costs 0 tokens per session (651 once invoked), scanned A, original, MIT.

A set of rules for PostgreSQL and SQLite database work, including raw SQL migrations and Row Level Security. Row Level Security is a database feature that restricts which rows each user or role can read or change.

In plain words
What is it for?
Use it when changing database schemas, writing SQL queries or migrations, or verifying that user, administrator, and background-job access stays within the intended boundaries.
Why use it?
It prevents application code from accidentally bypassing user-data isolation. It also defines how schema changes are made and how access rules should be checked afterward.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/bybren-llc/a-safe-pulse/12-database-sql
Clone the repo
git clone --depth 1 https://github.com/bybren-llc/a-safe-pulse

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for 12-database-sql

README.md
[![agentmods](https://agentmods.dev/badge/rules/bybren-llc/a-safe-pulse/12-database-sql.svg)](https://agentmods.dev/rules/bybren-llc/a-safe-pulse/12-database-sql)
Your own site
<a href="https://agentmods.dev/rules/bybren-llc/a-safe-pulse/12-database-sql"><img src="https://agentmods.dev/badge/rules/bybren-llc/a-safe-pulse/12-database-sql.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 651 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00651
Opus 5 $0.00000 $0.00326
Sonnet 5 $0.00000 $0.00130
Haiku 4.5 $0.00000 $0.00065

Measured yesterday against content hash b9e06e952ca4, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

12-database-sql scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/12-database-sql.mdc · 85 lines

How it starts

The opening of the file, as written. The whole thing — 85 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database and SQL Rules

These rules apply when working on database schemas, queries, and migrations.

Technology

  • Database: PostgreSQL (production), SQLite (development)
  • ORM: None -- direct pg queries
  • Migrations: Raw SQL files in src/db/migrations/
  • RLS: Row Level Security (MANDATORY for target architecture)

Row Level Security (RLS)

CRITICAL: RLS is mandatory for ALL tables containing user data.

RLS Context Helpers

Every database operation MUST use the appropriate context helper:

Helper Use Case
withUserContext User-scoped operations
withAdminContext Admin-scoped operations
withSystemContext Background/webhook operations

Zero Tolerance

  • No direct query calls without RLS context wrappers
  • No bypassing RLS policies for convenience
  • No using superuser credentials in application code

RLS Validation

After any schema change, validate RLS:

  • User isolation: User A cannot see User B's data
  • Admin access: Admin can see data within policy scope
  • System context: Background tasks use system context

Migration Workflow

# 1. Create a new migration file
# Use the next sequential number: XXX_description.sql
touch src/db/migrations/008_add_new_table.sql

# 2. Write the migration SQL (CREATE TABLE, ALTER TABLE, etc.)
# 3. Add RLS policies if new table contains user data
# 4. Register the migration in src/db/migrations/index.ts
# 5. Test locally
npm run dev

# 6. Commit
git add src/db/migrations/
git commit -m "feat(db): description [ASP-XXX]"

Migration Rules

  • Never use DROP TABLE without a backup strategy
  • Never apply manual DDL in production outside of migrations
  • Always add proper indexes for query patterns
  • Add RLS policies for every new table with user data
  • Schema changes REQUIRE System Architect approval
  • Follow naming convention: XXX_description.sql (e.g., 008_add_audit_log.sql)

Read the full file on GitHub · 85 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 85 lines · 0 tokens per session scan A b9e06e952ca4

Subscribe to this mod's changes

12-database-sql is a cursor rule published in the GitHub repository bybren-llc/a-safe-pulse (9 stars, last pushed 5mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 651 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-04.