diff --git a/collab-guard/src/server/core/extension-bridge.ts b/collab-guard/src/server/core/extension-bridge.ts index a900933..afbc93a 100644 --- a/collab-guard/src/server/core/extension-bridge.ts +++ b/collab-guard/src/server/core/extension-bridge.ts @@ -148,14 +148,15 @@ export const pollPendingActions = async ( const client = await getSupabaseAdmin(); if (!client) return []; + // Extension sends subreddit_id = t5_xxx and subreddit_name = display name. + // Old rows (before subreddit_name column was added) stored the display name + // in subreddit_id. Match either pattern so both old and new rows are picked up. const { data, error } = await client .from('pending_queue_actions') .select('*') - // cgbaov2 schema stores the subreddit name in subreddit_id. - // Reddit/Devvit may lowercase subredditName in scheduler context while - // the extension preserves URL casing, so match this boundary - // case-insensitively. - .ilike('subreddit_id', scope.subredditName) + .or( + `subreddit_name.ilike.${scope.subredditName},subreddit_id.ilike.${scope.subredditName},subreddit_id.ilike.${scope.subredditId}` + ) .eq('status', 'pending') .order('requested_at', { ascending: true }) .limit(POLL_LIMIT); diff --git a/supabase/migrations/20260526000001_fix_pending_queue_actions_schema.sql b/supabase/migrations/20260526000001_fix_pending_queue_actions_schema.sql new file mode 100644 index 0000000..710bfa5 --- /dev/null +++ b/supabase/migrations/20260526000001_fix_pending_queue_actions_schema.sql @@ -0,0 +1,21 @@ +-- Fix pending_queue_actions schema mismatches +-- +-- The original migration created id as UUID, but the enqueue edge function +-- inserts a sha256 hex string (not a valid UUID), causing every enqueue call +-- to return 500. subreddit_name and verdict_hash were also missing columns +-- that the handler inserts, producing the same error. +-- +-- The poller in extension-bridge.ts was also querying subreddit_id ILIKE +-- subredditName, but the handler stores the t5_ Reddit ID in subreddit_id +-- and the display name in subreddit_name, so the query never matched. +-- That code fix is in collab-guard/src/server/core/extension-bridge.ts. + +-- 1. Change id from UUID to TEXT (handler inserts sha256 hex, not a UUID) +ALTER TABLE public.pending_queue_actions ALTER COLUMN id TYPE TEXT USING id::TEXT; +ALTER TABLE public.pending_queue_actions ALTER COLUMN id DROP DEFAULT; + +-- 2. Add subreddit_name (handler inserts body.subredditName here) +ALTER TABLE public.pending_queue_actions ADD COLUMN IF NOT EXISTS subreddit_name TEXT; + +-- 3. Add verdict_hash (handler inserts body.verdictHash here) +ALTER TABLE public.pending_queue_actions ADD COLUMN IF NOT EXISTS verdict_hash TEXT;