Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions collab-guard/src/server/core/extension-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Loading