diff --git a/supabase/migrations/093_wrap_rls_perf_initplan.sql b/supabase/migrations/093_wrap_rls_perf_initplan.sql new file mode 100644 index 000000000..69f93b40f --- /dev/null +++ b/supabase/migrations/093_wrap_rls_perf_initplan.sql @@ -0,0 +1,548 @@ +-- Wrap auth.uid()/current_setting() in RLS policy predicates in (select ...) so +-- Postgres evaluates each once per statement (an InitPlan) instead of once per row -- +-- the Supabase-documented RLS perf pattern. Covers USING and WITH CHECK. Predicate- +-- equivalent (row visibility unchanged). Generated by 'pgrls fix --rule PERF001' +-- (pgrls 0.44.0) and verified on Postgres 16 (PERF001 -> 0). + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own agent conversations' on public.agent_conversations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own agent conversations" ON public.agent_conversations + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own installs' on public.agent_installs so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own installs" ON public.agent_installs + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'agent_outcomes_authenticated_insert' on public.agent_outcomes so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY agent_outcomes_authenticated_insert ON public.agent_outcomes + WITH CHECK ((SELECT auth.role()) = CAST('authenticated' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'agent_outcomes_authenticated_select' on public.agent_outcomes so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY agent_outcomes_authenticated_select ON public.agent_outcomes + USING ((SELECT auth.role()) = CAST('authenticated' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own workflows' on public.agent_workflows so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own workflows" ON public.agent_workflows + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'algorithm_weights_insert' on public.algorithm_weights so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY algorithm_weights_insert ON public.algorithm_weights + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'algorithm_weights_select' on public.algorithm_weights so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY algorithm_weights_select ON public.algorithm_weights + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'algorithm_weights_update' on public.algorithm_weights so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY algorithm_weights_update ON public.algorithm_weights + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own API keys' on public.api_keys so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own API keys" ON public.api_keys + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'author_follows_delete' on public.author_follows so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY author_follows_delete ON public.author_follows + USING ((SELECT auth.uid()) = follower_id); + +-- [PERF001] Wrap auth function call(s) in policy 'author_follows_insert' on public.author_follows so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY author_follows_insert ON public.author_follows + WITH CHECK ((SELECT auth.uid()) = follower_id); + +-- [PERF001] Wrap auth function call(s) in policy 'author_profiles_owner' on public.author_profiles so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY author_profiles_owner ON public.author_profiles + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'background_agents_owner_delete' on public.background_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY background_agents_owner_delete ON public.background_agents + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'background_agents_owner_insert' on public.background_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY background_agents_owner_insert ON public.background_agents + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'background_agents_owner_select' on public.background_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY background_agents_owner_select ON public.background_agents + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'background_agents_owner_update' on public.background_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY background_agents_owner_update ON public.background_agents + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own briefings' on public.briefings so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own briefings" ON public.briefings + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'buddy_leaderboard_service_write' on public.buddy_leaderboard so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY buddy_leaderboard_service_write ON public.buddy_leaderboard + USING ((SELECT auth.role()) = CAST('service_role' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own scores' on public.client_scores so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own scores" ON public.client_scores + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own scores' on public.client_scores so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own scores" ON public.client_scores + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Authenticated users can insert insights' on public.collective_insights so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Authenticated users can insert insights" ON public.collective_insights + WITH CHECK ((SELECT auth.role()) = CAST('authenticated' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'Authenticated users can update insights' on public.collective_insights so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Authenticated users can update insights" ON public.collective_insights + USING ((SELECT auth.role()) = CAST('authenticated' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'service_role_consultation_clients' on public.consultation_clients so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY service_role_consultation_clients ON public.consultation_clients + USING ((SELECT auth.role()) = CAST('service_role' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'service_role_consultation_messages' on public.consultation_messages so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY service_role_consultation_messages ON public.consultation_messages + USING ((SELECT auth.role()) = CAST('service_role' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'service_role_consultation_threads' on public.consultation_threads so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY service_role_consultation_threads ON public.consultation_threads + USING ((SELECT auth.role()) = CAST('service_role' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'content_bookmarks_owner' on public.content_bookmarks so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_bookmarks_owner ON public.content_bookmarks + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'content_comments_delete' on public.content_comments so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_comments_delete ON public.content_comments + USING ((SELECT auth.uid()) = user_id OR EXISTS (SELECT 1 FROM content_items AS ci WHERE ci.id = content_comments.content_id AND ci.user_id = auth.uid())); + +-- [PERF001] Wrap auth function call(s) in policy 'content_comments_insert' on public.content_comments so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_comments_insert ON public.content_comments + WITH CHECK ((SELECT auth.uid()) = user_id AND EXISTS (SELECT 1 FROM content_items AS ci WHERE ci.id = content_comments.content_id AND ci.is_published = TRUE)); + +-- [PERF001] Wrap auth function call(s) in policy 'content_comments_update' on public.content_comments so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_comments_update ON public.content_comments + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'content_items_delete' on public.content_items so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_items_delete ON public.content_items + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'content_items_insert' on public.content_items so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_items_insert ON public.content_items + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'content_items_select' on public.content_items so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_items_select ON public.content_items + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'content_items_update' on public.content_items so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_items_update ON public.content_items + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'content_likes_delete' on public.content_likes so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_likes_delete ON public.content_likes + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'content_likes_insert' on public.content_likes so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY content_likes_insert ON public.content_likes + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users manage own folders' on public.conversation_folders so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users manage own folders" ON public.conversation_folders + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can create own conversations' on public.conversations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can create own conversations" ON public.conversations + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own conversations' on public.conversations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own conversations" ON public.conversations + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own conversations' on public.conversations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own conversations" ON public.conversations + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view own conversations' on public.conversations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view own conversations" ON public.conversations + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own agents' on public.custom_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own agents" ON public.custom_agents + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view own devices' on public.device_fingerprints so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view own devices" ON public.device_fingerprints + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own discord link' on public.discord_user_links so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own discord link" ON public.discord_user_links + USING (user_id = (SELECT auth.uid())); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view own discord link' on public.discord_user_links so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view own discord link" ON public.discord_user_links + USING (user_id = (SELECT auth.uid())); + +-- [PERF001] Wrap auth function call(s) in policy 'Authors can delete their own tools' on public.forged_tools so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Authors can delete their own tools" ON public.forged_tools + USING ((SELECT auth.uid()) = author_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Authors can insert their own tools' on public.forged_tools so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Authors can insert their own tools" ON public.forged_tools + WITH CHECK ((SELECT auth.uid()) = author_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Authors can update their own tools' on public.forged_tools so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Authors can update their own tools" ON public.forged_tools + USING ((SELECT auth.uid()) = author_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users read own images' on public.generated_images so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users read own images" ON public.generated_images + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'kbot_memory_own' on public.kbot_memory so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY kbot_memory_own ON public.kbot_memory + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Service role can write synthesis state' on public.kbot_synthesis_state so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Service role can write synthesis state" ON public.kbot_synthesis_state + USING ((SELECT auth.role()) = CAST('service_role' AS text)) + WITH CHECK ((SELECT auth.role()) = CAST('service_role' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own contradictions' on public.knowledge_contradictions so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own contradictions" ON public.knowledge_contradictions + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own contradictions' on public.knowledge_contradictions so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own contradictions" ON public.knowledge_contradictions + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own contradictions' on public.knowledge_contradictions so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own contradictions" ON public.knowledge_contradictions + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own contradictions' on public.knowledge_contradictions so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own contradictions" ON public.knowledge_contradictions + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own entities' on public.knowledge_graph_entities so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own entities" ON public.knowledge_graph_entities + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own entities' on public.knowledge_graph_entities so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own entities" ON public.knowledge_graph_entities + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own entities' on public.knowledge_graph_entities so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own entities" ON public.knowledge_graph_entities + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own entities' on public.knowledge_graph_entities so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own entities" ON public.knowledge_graph_entities + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own relations' on public.knowledge_graph_relations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own relations" ON public.knowledge_graph_relations + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own relations' on public.knowledge_graph_relations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own relations" ON public.knowledge_graph_relations + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own relations' on public.knowledge_graph_relations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own relations" ON public.knowledge_graph_relations + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own relations' on public.knowledge_graph_relations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own relations" ON public.knowledge_graph_relations + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own items' on public.knowledge_items so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own items" ON public.knowledge_items + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own items' on public.knowledge_items so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own items" ON public.knowledge_items + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own items' on public.knowledge_items so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own items" ON public.knowledge_items + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own items' on public.knowledge_items so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own items" ON public.knowledge_items + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own topics' on public.knowledge_topics so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own topics" ON public.knowledge_topics + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own topics' on public.knowledge_topics so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own topics" ON public.knowledge_topics + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own topics' on public.knowledge_topics so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own topics" ON public.knowledge_topics + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own topics' on public.knowledge_topics so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own topics" ON public.knowledge_topics + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users join shares' on public.live_share_participants so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users join shares" ON public.live_share_participants + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'View own participation' on public.live_share_participants so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "View own participation" ON public.live_share_participants + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Owners manage live shares' on public.live_shares so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Owners manage live shares" ON public.live_shares + USING ((SELECT auth.uid()) = owner_id) + WITH CHECK ((SELECT auth.uid()) = owner_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view own purchases' on public.message_purchases so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view own purchases" ON public.message_purchases + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view their own message states' on public.message_states so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view their own message states" ON public.message_states + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own notifications' on public.notifications so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own notifications" ON public.notifications + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view their own errors' on public.platform_errors so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view their own errors" ON public.platform_errors + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own workflows' on public.platform_workflows so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own workflows" ON public.platform_workflows + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own workflows' on public.platform_workflows so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own workflows" ON public.platform_workflows + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own workflows' on public.platform_workflows so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own workflows" ON public.platform_workflows + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own workflows' on public.platform_workflows so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own workflows" ON public.platform_workflows + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete own procedures' on public.procedures so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete own procedures" ON public.procedures + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own procedures' on public.procedures so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own procedures" ON public.procedures + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read own procedures' on public.procedures so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read own procedures" ON public.procedures + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own procedures' on public.procedures so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own procedures" ON public.procedures + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can read their own project files' on public.project_files so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can read their own project files" ON public.project_files + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can create own signals' on public.response_signals so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can create own signals" ON public.response_signals + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own signals' on public.response_signals so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own signals" ON public.response_signals + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view own signals' on public.response_signals so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view own signals" ON public.response_signals + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'routing_weights_authenticated_insert' on public.routing_weights so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY routing_weights_authenticated_insert ON public.routing_weights + WITH CHECK ((SELECT auth.role()) = CAST('authenticated' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'routing_weights_authenticated_select' on public.routing_weights so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY routing_weights_authenticated_select ON public.routing_weights + USING ((SELECT auth.role()) = CAST('authenticated' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'routing_weights_authenticated_update' on public.routing_weights so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY routing_weights_authenticated_update ON public.routing_weights + USING ((SELECT auth.role()) = CAST('authenticated' AS text)); + +-- [PERF001] Wrap auth function call(s) in policy 'sandboxes_owner_delete' on public.sandboxes so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY sandboxes_owner_delete ON public.sandboxes + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'sandboxes_owner_insert' on public.sandboxes so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY sandboxes_owner_insert ON public.sandboxes + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'sandboxes_owner_select' on public.sandboxes so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY sandboxes_owner_select ON public.sandboxes + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'sandboxes_owner_update' on public.sandboxes so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY sandboxes_owner_update ON public.sandboxes + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own scheduled tasks' on public.scheduled_tasks so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own scheduled tasks" ON public.scheduled_tasks + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can create their own shared conversations' on public.shared_conversations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can create their own shared conversations" ON public.shared_conversations + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can delete their own shared conversations' on public.shared_conversations so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can delete their own shared conversations" ON public.shared_conversations + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_accounts_delete' on public.social_accounts so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_accounts_delete ON public.social_accounts + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_accounts_insert' on public.social_accounts so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_accounts_insert ON public.social_accounts + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_accounts_select' on public.social_accounts so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_accounts_select ON public.social_accounts + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_accounts_update' on public.social_accounts so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_accounts_update ON public.social_accounts + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_analytics_insert' on public.social_analytics so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_analytics_insert ON public.social_analytics + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_analytics_select' on public.social_analytics so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_analytics_select ON public.social_analytics + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_oauth_states_delete' on public.social_oauth_states so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_oauth_states_delete ON public.social_oauth_states + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_oauth_states_insert' on public.social_oauth_states so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_oauth_states_insert ON public.social_oauth_states + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_oauth_states_select' on public.social_oauth_states so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_oauth_states_select ON public.social_oauth_states + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_posts_delete' on public.social_posts so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_posts_delete ON public.social_posts + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_posts_insert' on public.social_posts so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_posts_insert ON public.social_posts + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_posts_select' on public.social_posts so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_posts_select ON public.social_posts + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'social_posts_update' on public.social_posts so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY social_posts_update ON public.social_posts + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view own subscription' on public.subscriptions so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view own subscription" ON public.subscriptions + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can view their own task executions' on public.task_executions so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can view their own task executions" ON public.task_executions + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'user_agents_delete' on public.user_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY user_agents_delete ON public.user_agents + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'user_agents_insert' on public.user_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY user_agents_insert ON public.user_agents + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'user_agents_select' on public.user_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY user_agents_select ON public.user_agents + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'user_agents_update' on public.user_agents so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY user_agents_update ON public.user_agents + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage own engine state' on public.user_engine_state so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage own engine state" ON public.user_engine_state + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users manage own file folders' on public.user_file_folders so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users manage own file folders" ON public.user_file_folders + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users manage own files' on public.user_files so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users manage own files" ON public.user_files + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own goals' on public.user_goals so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own goals" ON public.user_goals + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage own memory' on public.user_memory so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage own memory" ON public.user_memory + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can insert own profile' on public.user_profiles so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can insert own profile" ON public.user_profiles + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can update own profile' on public.user_profiles so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can update own profile" ON public.user_profiles + USING ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users can manage their own workflow runs' on public.workflow_runs so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users can manage their own workflow runs" ON public.workflow_runs + USING ((SELECT auth.uid()) = user_id) + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Members view members' on public.workspace_members so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Members view members" ON public.workspace_members + USING (user_id = (SELECT auth.uid()) OR is_workspace_member(workspace_id)); + +-- [PERF001] Wrap auth function call(s) in policy 'Users accept invitations' on public.workspace_members so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users accept invitations" ON public.workspace_members + WITH CHECK ((SELECT auth.uid()) = user_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Members view workspace' on public.workspaces so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Members view workspace" ON public.workspaces + USING ((SELECT auth.uid()) = owner_id OR is_workspace_member(id)); + +-- [PERF001] Wrap auth function call(s) in policy 'Owner updates workspace' on public.workspaces so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Owner updates workspace" ON public.workspaces + USING ((SELECT auth.uid()) = owner_id); + +-- [PERF001] Wrap auth function call(s) in policy 'Users create workspaces' on public.workspaces so Postgres can cache the result for the whole statement instead of re-evaluating per row. +ALTER POLICY "Users create workspaces" ON public.workspaces + WITH CHECK ((SELECT auth.uid()) = owner_id);