Supabase & PostgreSQL Multi-Tenant Row Level Security (RLS) Policy Architect
Transforms Cursor or Claude into a veteran PostgreSQL Database Administrator generating ironclad Row Level Security (RLS) policies that prevent cross-tenant data leaks and eliminate table scan bottlenecks.
Parametric Customizer & Compiler Live Tool
Adjust the variables below. The prompt code and API payload update dynamically in real time.
Specifies multi-tenant isolation pattern.
Identifies where user claims originate.
Ensures index optimizations prevent full table sequential scans.
# SUPABASE & POSTGRESQL ROW LEVEL SECURITY (RLS) ARCHITECT You are a Principal Database Administrator and Application Security Engineer specializing in PostgreSQL 16+ and Supabase multi-tenant architectures. ### SCHEMA CONTEXT: - Multi-Tenancy Model: Shared Database, Shared Schema with tenant_id Foreign Key - Authentication Mechanism: Supabase Auth with auth.uid() & app_metadata JWT claims - Performance Requirement: High-Throughput OLTP (Sub-5ms RLS evaluation on millions of rows) ### MANDATORY RLS PRODUCTION STANDARDS: 1. **Strict Table-Level RLS Enforcement**: - Every newly created table MUST execute `ALTER TABLE <table_name> ENABLE ROW LEVEL SECURITY;` and `ALTER TABLE <table_name> FORCE ROW LEVEL SECURITY;` (protecting table owners from accidental bypass). 2. **Separation of CRUD Policies**: - Do NOT use generic `FOR ALL` policies. Create distinct policies for `SELECT`, `INSERT`, `UPDATE`, and `DELETE`. - In `INSERT` policies, enforce `WITH CHECK` validating that `tenant_id` matches user's session claims. - In `UPDATE` policies, supply BOTH `USING` (who can select to update) and `WITH CHECK` (preventing tenant re-assignment). 3. **Index Optimization for RLS Predicates**: - Every foreign key and tenant discriminator used in `USING` clauses MUST have a supporting B-tree index (e.g., `CREATE INDEX ON orders (tenant_id, created_at DESC)`). 4. **Preventing Subquery N+1 Cascades**: - Wrap reusable tenant lookups inside `SECURITY DEFINER` functions with `STABLE` volatility and explicit `SET search_path = public` to prevent function search-path hijack vulnerabilities. ### OUTPUT SPECIFICATIONS: Output complete, migration-ready SQL with comments explaining security invariants.
Open source Firebase alternative with Postgres database and built-in Auth.
Leonardo Phoenix & Flux: Generate photorealistic studio assets with 150 daily free credits. Zero setup required.
π 3-Step Production Execution Blueprint
How senior engineers and top creators calibrate, customize, and verify this prompt formula in production.
Target Engine Calibration
Drop this prompt into your project root as `.cursorrules` or load it into Claude 3.5 Sonnet / DeepSeek-R1 system instructions.
Dynamic Parameterization
Adjust the dynamic variables (framework, database, and client state) to match your active codebase architecture.
Sanity & Boundary Check
Run a verification query asking the model to declare its architectural constraints before it generates the first line of code.
βοΈ Recommended API Hyperparameter Calibration
Verified 2026 SettingsCALIBRATION INSIGHT: Low temperature ensures deterministic syntax, accurate AST parsing, and zero hallucinated API methods.
πΈ Real Sample Outputs & Verified Results
Visual evidence and benchmark responses generated using this exact prompt formula.
π¬ Prompt Engineering Anatomy
Why this prompt consistently delivers high-tier results: technical parameter breakdown.
FORCE ROW LEVEL SECURITY Standard ENABLE ROW LEVEL SECURITY does not apply to table owners or superusers. Adding FORCE ROW LEVEL SECURITY ensures even migrations and administrative queries honor tenant boundaries.
Security Definer Search Path Hardening Functions running with elevated privileges must explicitly set search_path = public to avoid malicious code execution via schema hijacking.
β οΈ Critical Anti-Patterns & Execution Traps
The top 3 engineering mistakes to avoid when deploying this category of prompt into production.
Context Window Flooding
Pasting 50 unminified files into the prompt degrades attention, causing the LLM to ignore core TypeScript rules.
Missing Delimiter Isolation
Letting user instructions mix directly with system rules triggers instruction drift and hallucinations.
Over-Relying on Outdated Paradigms
Allowing the model to use deprecated React 18 patterns (e.g. useEffect for data fetching) creates security vulnerabilities.
π¬ Frequently Asked Questions
Troubleshooting common edge cases, model incompatibilities, and best practices.
Does this prompt eliminate PostgreSQL N+1 RLS query slowdowns?
Yes, by generating composite indexes specifically tailored to auth.uid() and tenant_id lookups.
π οΈ Recommended Companion Micro-Tools
Complementary client-side tools designed to test, sanitize, or choreograph outputs from this prompt.
Vibe Coding Prompt Architect (.cursorrules Studio)
Generate production-grade .cursorrules, .windsurfrules, and CLAUDE.md for Next.js 15, FastAPI, and Go with zero-hallucination guardrails.
Launch Tool β‘System Prompt Security Auditor & Jailbreak Scanner
Scan LLM instructions for prompt injection, persona hijacking, and instruction leaks. Score defense 0-100 and auto-harden in 0ms.
Launch Tool β‘Token & API Cost Calculator
Calculate live token counts & cost comparisons across GPT-4o, Claude 3.5, and DeepSeek-R1 with prompt caching discounts.
Launch Tool β‘Cursor AI & Claude 3.5 Sonnet Pro Bundle
Supercharge your workflow with instant codebase indexing, multi-file edits, and automated system rules.
Explore Related Database Security & RLS Prompts View all β
Claude 3.5 Sonnet Senior Staff Full-Stack Refactoring Architect
Specialized prompt framework for Claude 3.5 Sonnet and Claude 3.7. Transforms messy legacy codebases into modular, testable, high-performance systems with automated regression tests.
cursorCursor AI (.cursorrules) for Next.js 15, React 19 & Tailwind CSS
Stops Cursor from writing outdated Next.js 13 patterns, Pages Router syntax, or deprecated React hooks. Enforces strict TypeScript, Server Actions, and modular clean architecture.
deepseekDeepSeek-R1 Autonomous Deep Research & Synthesis Engine
DeepSeek-R1 chain-of-thought framework designed to force deep reflection, counterfactual auditing, and hypothesis testing before producing production-ready research reports.