-- 181_clamp_bad_listing_dates.sql
-- LOW audit R2 (#6): null out implausible listing_date/publish_date left by scrapers
-- before the clamp guard landed (Avito 1970-epoch: ~698 rows; near-future: ~79 rows).
-- Idempotent: re-running is a no-op once values are already NULL / in-window.

BEGIN;

UPDATE listings SET listing_date = NULL
 WHERE listing_date IS NOT NULL
   AND (listing_date < DATE '2010-01-01' OR listing_date > CURRENT_DATE + 2);

UPDATE listings SET publish_date = NULL
 WHERE publish_date IS NOT NULL
   AND (publish_date < DATE '2010-01-01' OR publish_date > CURRENT_DATE + 2);

COMMIT;
