rls-policy-optimizer

Generate Supabase RLS migrations replacing auth.uid() with (select auth.uid()) in USING clauses.

Updated Oct 16, 2025
One-click install
npx skills add https://github.com/sanchezx1/v0-fullcolor-cotizador --skill rls-policy-optimizer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rls-policy-optimizer
Source: https://github.com/sanchezx1/v0-fullcolor-cotizador/tree/main/.claude/skills/rls-policy-optimizer
Command: npx skills add https://github.com/sanchezx1/v0-fullcolor-cotizador --skill rls-policy-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Optimiza políticas RLS de Supabase usando la construcción (select auth.uid()) para evitar reevaluaciones por fila y mejorar el performance.

Core Features & Use Cases

  • Performance improvement: reduce llamadas a auth.uid() por fila.
  • Tables afectadas: leads, cotizaciones, items_cotizacion, email_logs.

Quick Start

  1. Usar MCP Supabase para obtener las policies actuales, 2) crear migración para sustituir USING auth.uid() por USING ((select auth.uid()) = user_id), 3) aplicar migración y verificar con el advisor.

Frequently Asked Questions about rls-policy-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize Supabase RLS policies to reduce auth.uid() evaluation overhead?

Optimize RLS policies by replacing direct auth.uid() calls with the (select auth.uid()) pattern in USING clauses. This subquery approach evaluates auth.uid() once per policy instead of per row, significantly improving query performance across tables like leads, cotizaciones, and items_cotizacion.

Why does wrapping auth.uid() in a SELECT subquery improve RLS performance?

The (select auth.uid()) pattern forces the database to execute auth.uid() once and cache the result, rather than re-evaluating it for every row during policy filtering. This reduces function call overhead and accelerates row-level security checks on large datasets.

What tables and RLS scenarios does this optimization cover?

This optimization applies to leads, cotizaciones, items_cotizacion, and email_logs tables. It addresses auth.uid() reevaluation issues and aligns with PLAN_MEJORAS tasks 1.3 and 2.1, ensuring consistent performance improvements across your security policies.

How do I implement RLS policy optimizations with migrations in Supabase?

Create migration files at database/migrations/YYYYMMDD_optimize_rls_<tabla>.sql containing DROP POLICY and CREATE POLICY blocks that replace auth.uid() with (select auth.uid()). Apply migrations using mcp_supabase_apply_migration and verify results via mcp_supabase_get_advisors type="performance".

Can I apply RLS optimizations without breaking existing security policies?

Yes. The optimization maintains the same security logic while improving execution. Use mcp_supabase_get_advisors to retrieve current policies, then generate migrations that replace only the auth.uid() evaluation pattern. Drop and recreate policies atomically to ensure no security gaps.

How do I verify that RLS optimizations actually improved performance?

After applying migrations, run mcp_supabase_get_advisors with type="performance" to retrieve performance metrics and confirm the optimization reduced auth.uid() evaluation costs. Document results and performance gains in docs/PLAN_MEJORAS.md for tracking and auditing.