diff --git a/backend/migrations/0016_crawler_jobs_drop_failed_state.sql b/backend/migrations/0016_crawler_jobs_drop_failed_state.sql new file mode 100644 index 0000000..bc64f55 --- /dev/null +++ b/backend/migrations/0016_crawler_jobs_drop_failed_state.sql @@ -0,0 +1,15 @@ +-- The original 0012 partial index covers `state IN ('pending','failed')`, +-- but `ack_failed` in src/crawler/jobs.rs only writes `dead` or +-- `pending` — `failed` is never set. The index branch on `failed` +-- never matches any row, so it's dead weight on every write. +-- +-- Drop and recreate the index without the dead branch. The CHECK +-- constraint on `state` still allows `'failed'` so a future migration +-- can adopt that terminal-but-retryable state without a second +-- schema change. + +DROP INDEX IF EXISTS crawler_jobs_ready_idx; + +CREATE INDEX crawler_jobs_ready_idx + ON crawler_jobs (scheduled_at) + WHERE state = 'pending';