Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(db): add the missing cloro_pending_tasks migration (#692)

Gökhan Geyik8d00fe66ab80
diff --git a/supabase/migrations/00049_cloro_pending_tasks.sql b/supabase/migrations/00049_cloro_pending_tasks.sql
new file mode 100644
index 000000000..04d57fba2
--- /dev/null
+++ b/supabase/migrations/00049_cloro_pending_tasks.sql
@@ -0,0 +1,35 @@
+-- Cloro pending-task queue (#652) — backfills DDL that was only ever applied
+-- to the hosted database and never committed here, so a fresh install created
+-- every other table and then failed on this one:
+--
+-- PGRST205: Could not find the table 'public.cloro_pending_tasks'
+--
+-- The table is a transient submit-queue: the tracking worker inserts a row per
+-- task handed to the scraper, /cloro/callback deletes it when the result
+-- arrives, and cleanupStalePendingTasks sweeps whatever the provider never
+-- delivered. It holds no history — a fresh install starting empty is correct.
+--
+-- Guarded with IF NOT EXISTS throughout so databases that already have the
+-- table (every deployment predating this file) apply it as a no-op.
+
+CREATE TABLE IF NOT EXISTS public.cloro_pending_tasks (
+ task_id text PRIMARY KEY,
+ prompt_id uuid NOT NULL REFERENCES public.prompts(id) ON DELETE CASCADE,
+ brand_id uuid NOT NULL REFERENCES public.brands(id) ON DELETE CASCADE,
+ scraper_id text NOT NULL,
+ region text,
+ submitted_at timestamptz NOT NULL DEFAULT now()
+);
+
+-- brand_id: the drain loop polls "what is still pending for this brand" on
+-- every tick of a run. submitted_at: the stale sweep and the ghost-task exit
+-- both filter by age (#687).
+CREATE INDEX IF NOT EXISTS idx_cloro_pending_tasks_brand_id
+ ON public.cloro_pending_tasks (brand_id);
+CREATE INDEX IF NOT EXISTS idx_cloro_pending_tasks_submitted_at
+ ON public.cloro_pending_tasks (submitted_at);
+
+-- RLS on with no policies: only the service role touches this table, and it
+-- bypasses RLS. Anything reaching it through an anon/authenticated key gets
+-- nothing, which is the intent — task ids are provider-side handles.
+ALTER TABLE public.cloro_pending_tasks ENABLE ROW LEVEL SECURITY;
diff --git a/supabase/schema.sql b/supabase/schema.sql
index a96e78f25..e3684a78b 100644
--- a/supabase/schema.sql
+++ b/supabase/schema.sql
@@ -5062,3 +5062,42 @@ CREATE TABLE public.dataforseo_competition_cache (
ALTER TABLE public.dataforseo_competition_cache ENABLE ROW LEVEL SECURITY;
+-- ─────────────────────────────────────────────────────────────────────────
+-- migrations/00049_cloro_pending_tasks.sql
+-- ─────────────────────────────────────────────────────────────────────────
+-- Cloro pending-task queue (#652) — backfills DDL that was only ever applied
+-- to the hosted database and never committed here, so a fresh install created
+-- every other table and then failed on this one:
+--
+-- PGRST205: Could not find the table 'public.cloro_pending_tasks'
+--
+-- The table is a transient submit-queue: the tracking worker inserts a row per
+-- task handed to the scraper, /cloro/callback deletes it when the result
+-- arrives, and cleanupStalePendingTasks sweeps whatever the provider never
+-- delivered. It holds no history — a fresh install starting empty is correct.
+--
+-- Guarded with IF NOT EXISTS throughout so databases that already have the
+-- table (every deployment predating this file) apply it as a no-op.
+
+CREATE TABLE IF NOT EXISTS public.cloro_pending_tasks (
+ task_id text PRIMARY KEY,
+ prompt_id uuid NOT NULL REFERENCES public.prompts(id) ON DELETE CASCADE,
+ brand_id uuid NOT NULL REFERENCES public.brands(id) ON DELETE CASCADE,
+ scraper_id text NOT NULL,
+ region text,
+ submitted_at timestamptz NOT NULL DEFAULT now()
+);
+
+-- brand_id: the drain loop polls "what is still pending for this brand" on
+-- every tick of a run. submitted_at: the stale sweep and the ghost-task exit
+-- both filter by age (#687).
+CREATE INDEX IF NOT EXISTS idx_cloro_pending_tasks_brand_id
+ ON public.cloro_pending_tasks (brand_id);
+CREATE INDEX IF NOT EXISTS idx_cloro_pending_tasks_submitted_at
+ ON public.cloro_pending_tasks (submitted_at);
+
+-- RLS on with no policies: only the service role touches this table, and it
+-- bypasses RLS. Anything reaching it through an anon/authenticated key gets
+-- nothing, which is the intent — task ids are provider-side handles.
+ALTER TABLE public.cloro_pending_tasks ENABLE ROW LEVEL SECURITY;
+
diff --git a/web/src/types/supabase.ts b/web/src/types/supabase.ts
index d66907fa4..e90c78f79 100644
--- a/web/src/types/supabase.ts
+++ b/web/src/types/supabase.ts
@@ -346,6 +346,48 @@ export type Database = {
},
];
};
+ cloro_pending_tasks: {
+ Row: {
+ brand_id: string;
+ prompt_id: string;
+ region: string | null;
+ scraper_id: string;
+ submitted_at: string;
+ task_id: string;
+ };
+ Insert: {
+ brand_id: string;
+ prompt_id: string;
+ region?: string | null;
+ scraper_id: string;
+ submitted_at?: string;
+ task_id: string;
+ };
+ Update: {
+ brand_id?: string;
+ prompt_id?: string;
+ region?: string | null;
+ scraper_id?: string;
+ submitted_at?: string;
+ task_id?: string;
+ };
+ Relationships: [
+ {
+ foreignKeyName: 'cloro_pending_tasks_brand_id_fkey';
+ columns: ['brand_id'];
+ isOneToOne: false;
+ referencedRelation: 'brands';
+ referencedColumns: ['id'];
+ },
+ {
+ foreignKeyName: 'cloro_pending_tasks_prompt_id_fkey';
+ columns: ['prompt_id'];
+ isOneToOne: false;
+ referencedRelation: 'prompts';
+ referencedColumns: ['id'];
+ },
+ ];
+ };
competitors: {
Row: {
brand_id: string;