Agent skill
rls-policy-optimizer
Optimiza políticas RLS de Supabase usando el patrón (select auth.uid()) para mejor performance. Usa cuando trabajes con RLS policies, auth.uid() reevaluación, o tareas 1.3 y 2.1 del PLAN_MEJORAS.md.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/design/rls-policy-optimizer
SKILL.md
RLS Policy Optimizer
Skill para optimizar Row Level Security policies en Supabase evitando reevaluación de auth.uid() por cada fila.
Problema
-- MALO: auth.uid() se evalúa por cada fila
USING (auth.uid() = user_id)
Solución
-- BUENO: (select auth.uid()) se evalúa una vez
USING ((select auth.uid()) = user_id)
Tablas Afectadas en este Proyecto
leads- policies: Users insert/read/updatecotizaciones- policies: Users insert/readitems_cotizacion- policies: Users insert/reademail_logs- policies: Admins manage
Instrucciones
- Usar MCP Supabase para obtener policies actuales de la tabla
- Crear migración en
database/migrations/YYYYMMDD_optimize_rls_<tabla>.sql - Incluir DROP POLICY + CREATE POLICY con el fix
- Aplicar con
mcp_supabase_apply_migration - Verificar con
mcp_supabase_get_advisorstype="performance" - Documentar en
docs/PLAN_MEJORAS.md
Template de Migración
-- Optimizar RLS: usar (select auth.uid()) en lugar de auth.uid()
-- Referencia: https://supabase.com/docs/guides/database/postgres/row-level-security#call-functions-with-select
-- Backup implícito: recreamos la policy con la misma lógica optimizada
DROP POLICY IF EXISTS "Users read own <tabla>" ON public.<tabla>;
CREATE POLICY "Users read own <tabla>" ON public.<tabla>
FOR SELECT TO authenticated
USING ((select auth.uid()) = user_id);
Verificación
Después de aplicar, ejecutar advisor de Supabase y confirmar que no hay warnings de "auth function called per row".
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?