-- Fix items that were created with next_due_at ~= created_at (within 2 minutes) -- Run this after a backup. Adjust the WHERE clause if you want a different window. BEGIN; -- Preview rows to be changed SELECT id, item_key, course_id, stage, next_due_at, created_at FROM community.vocab_srs_item WHERE created_at >= now() - interval '3 days' AND abs(EXTRACT(EPOCH FROM (next_due_at - created_at))) < 120 ORDER BY created_at ASC LIMIT 200; -- Conservative update: set next_due_at to next calendar day at 08:00 UPDATE community.vocab_srs_item SET next_due_at = date_trunc('day', created_at + interval '1 day') + interval '8 hours' WHERE created_at >= now() - interval '3 days' AND abs(EXTRACT(EPOCH FROM (next_due_at - created_at))) < 120 RETURNING id, item_key, course_id, stage, next_due_at, created_at; COMMIT; -- After running, re-run backend/scripts/diag-srs-stats.js to validate counts.