guidelines-for-writing-supabase-database-functions

guidelines-for-writing-supabase-database-functions is a cursor rule for Cursor from fumito-ito/mdcvalult. It costs 0 tokens per session (810 once invoked), scanned A, original, MIT.

A set of rules for writing PostgreSQL database functions in Supabase, a service that provides hosted databases and backend tools. It emphasizes safer permissions, explicit database references, valid SQL, and limited side effects.

In plain words
What is it for?
Use it when creating or reviewing Supabase database functions, including functions that return data or support database triggers.
Why use it?
It helps avoid unclear permission behavior, accidental access through the wrong database schema, invalid queries, and unnecessary data changes when generating functions.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc). Also seen: mentions Cursor.

Good fit Use it when creating or reviewing Supabase database functions, including functions that return data or support database triggers.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/fumito-ito/mdcvalult/guidelines-for-writing-supabase-database-functions
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.

Clone the repo
git clone --depth 1 https://github.com/fumito-ito/mdcvalult

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 guidelines-for-writing-supabase-database-functions

README.md
[![agentmods](https://agentmods.dev/badge/rules/fumito-ito/mdcvalult/guidelines-for-writing-supabase-database-functions/github.svg)](https://agentmods.dev/rules/fumito-ito/mdcvalult/guidelines-for-writing-supabase-database-functions)
Your own site
<a href="https://agentmods.dev/rules/fumito-ito/mdcvalult/guidelines-for-writing-supabase-database-functions"><img src="https://agentmods.dev/badge/rules/fumito-ito/mdcvalult/guidelines-for-writing-supabase-database-functions/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for guidelines-for-writing-supabase-database-functions

Your own site · 80×15
<a href="https://agentmods.dev/rules/fumito-ito/mdcvalult/guidelines-for-writing-supabase-database-functions"><img src="https://agentmods.dev/badge/rules/fumito-ito/mdcvalult/guidelines-for-writing-supabase-database-functions.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 810 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.00810
Opus 5 $0.00000 $0.00405
Sonnet 5 $0.00000 $0.00162
Haiku 4.5 $0.00000 $0.00081

Measured 8d ago against content hash 401edbad1926, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

guidelines-for-writing-supabase-database-functions 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 8d ago.

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.

Origin

Copies of this mod

2 near-identical copies found in the catalogue:

mdc/guidelines-for-writing-supabase-database-functions.mdc · 138 lines

How it starts

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

Database: Create functions

You're a Supabase Postgres expert in writing database functions. Generate high-quality PostgreSQL functions that adhere to the following best practices:

General Guidelines

  1. Default to SECURITY INVOKER:

    • Functions should run with the permissions of the user invoking the function, ensuring safer access control.
    • Use SECURITY DEFINER only when explicitly required and explain the rationale.
  2. Set the search_path Configuration Parameter:

    • Always set search_path to an empty string (set search_path = '';).
    • This avoids unexpected behavior and security risks caused by resolving object references in untrusted or unintended schemas.
    • Use fully qualified names (e.g., schema_name.table_name) for all database objects referenced within the function.
  3. Adhere to SQL Standards and Validation:

    • Ensure all queries within the function are valid PostgreSQL SQL queries and compatible with the specified context (ie. Supabase).

Best Practices

  1. Minimize Side Effects:

    • Prefer functions that return results over those that modify data unless they serve a specific purpose (e.g., triggers).
  2. Use Explicit Typing:

    • Clearly specify input and output types, avoiding ambiguous or loosely typed parameters.
  3. Default to Immutable or Stable Functions:

    • Where possible, declare functions as IMMUTABLE or STABLE to allow better optimization by PostgreSQL. Use VOLATILE only if the function modifies data or has side effects.
  4. Triggers (if Applicable):

    • If the function is used as a trigger, include a valid CREATE TRIGGER statement that attaches the function to the desired table and event (e.g., BEFORE INSERT).

Example Templates

Simple Function with SECURITY INVOKER

create or replace function my_schema.hello_world()
returns text
language plpgsql
security invoker
set search_path = ''
as $$
begin
  return 'hello world';
end;
$$;

Function with Parameters and Fully Qualified Object Names

Read the full file on GitHub · 138 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. 8d ago First seen · 138 lines · 0 tokens per session scan A 401edbad1926

Subscribe to this mod's changes

guidelines-for-writing-supabase-database-functions is a cursor rule published in the GitHub repository fumito-ito/mdcvalult (33 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 810 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-08-30.