Skip to content

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

Merged
gkhngyk merged 1 commit into
mainfrom
fix/652-cloro-pending-tasks-migration
Aug 10, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/652-cloro-pending-tasks-migration

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

cloro_pending_tasks is written and read by four server modules (server.js, job-manager.js, pulse/engine.js, tracking-worker.js) but had no DDL anywhere in the repo — not in supabase/migrations/, not in schema.sql, not in the web types. It only ever existed because it was applied directly to the hosted database.

The consequence is that fresh self-host installs are broken: every other table is created, this one is not, and the server logs

PGRST205: Could not find the table 'public.cloro_pending_tasks' in the schema cache

The startup error is swallowed, so the failure surfaces later and more confusingly — /cloro/callback cannot resolve pending tasks, so scraper results are never stored and tracking silently produces nothing.

What's in here

  • supabase/migrations/00049_cloro_pending_tasks.sql — transcribed from the live database: both foreign keys (prompt_id, brand_id, each ON DELETE CASCADE), both indexes (brand_id for the drain loop's per-brand poll, submitted_at for the stale sweep and the ghost-task exit added in Tracking cycle: stop waiting on ghost Cloro tasks — cuts the nightly cycle from ~5h to ~1.5h #687), and RLS enabled with no policies — only the service role touches this table and it bypasses RLS, so anything arriving with an anon/authenticated key correctly gets nothing.
  • Regenerated supabase/schema.sql.
  • Added the table to web/src/types/supabase.ts, which was also missing it.

Every statement is guarded with IF NOT EXISTS, so deployments that already have the table apply this as a no-op.

Related issue

Closes #652 — reported by @Adarshhic

Type of change

  • fix — Bug fix

How to test

Fresh install (the path this fixes):

supabase db reset
cd server && npm run dev

No PGRST205 on startup, and a Cloro callback resolves its pending task instead of failing to find the row.

Existing database: applying the migration changes nothing — it is entirely IF NOT EXISTS.

Verification done

  • The migration has been applied to the hosted database (no-op as expected): the table, all three indexes and rowsecurity = true are unchanged, and the row that was pending at the time survived untouched. This keeps the migration history aligned with the repo rather than leaving the file unrecorded.
  • bash supabase/build-schema.sh is deterministic against the committed schema.sql — re-running it produces no diff, so the CI schema check passes.
  • yarn typecheck clean in web/.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/)
  • Commits follow Conventional Commits
  • yarn lint passes — no source files touched
  • yarn typecheck passes
  • yarn format:check passes — src/types/supabase.ts is Prettier-ignored as generated
  • Changes are focused — one concern per PR

The table was only ever applied to the hosted database and never committed
here, so a fresh self-host install created every other table and then failed
on this one with PGRST205, taking the Cloro webhook flow down with it — the
callback could not resolve pending tasks, so scraper results were never
stored.

DDL is transcribed from the live database (columns, both foreign keys, both
indexes, RLS enabled with no policies since only the service role touches
it) and guarded with IF NOT EXISTS so existing deployments apply it as a
no-op. Regenerated schema.sql and added the table to the web types, which
were missing it too.

Closes #652
@gkhngyk
gkhngyk merged commit 8d00fe6 into main Aug 10, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the fix/652-cloro-pending-tasks-migration branch August 10, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Missing cloro_pending_tasks migration breaks fresh installs

1 participant