-- =============================================================================
-- fix_mystateconnews_source_monitor.sql — re-search each state's CON sources
-- every 30 days (16 Nov 2026).
--
-- Turns on abos-api's WebSourceMonitorScheduler for the States collection's
-- "conSources" field: every 30 days each state's source pages are fetched
-- again, "conLastSearched" (shown as "Last searched") is updated, and if a
-- source page changed, "conReviewFlag" says which and staff get an Aggie
-- notification to review that state. Only sets the setting while the field
-- has none, so a change made in Aggie is kept. Idempotent.
-- =============================================================================
SET NAMES utf8mb4;
SET @site_id := (SELECT id FROM dim_web_sites WHERE public_site_key = 'YPIYmVgmODxVTxgcSNwb1yAKdCtFe1M9kGT5YnTxEkL3xxs9' LIMIT 1);
SET @states := (SELECT id FROM dim_web_collections WHERE site_id = @site_id AND collection_key = 'states' LIMIT 1);

UPDATE dim_web_collection_fields
SET config_json = '{"monitorSources":{"days":30,"checkedField":"conLastSearched","flagField":"conReviewFlag","hashField":"conSourceHashes"}}'
WHERE collection_id = @states AND field_key = 'conSources' AND (config_json IS NULL OR config_json NOT LIKE '%monitorSources%');
