INSERT INTO SUNO_PROD.PROD.BOT_STATUS_CHANGES (
    user_id,
    status_changed_at,
    matching_features,
    prev_matching_features,
    meets_bot_definition,
    prev_meets_bot_definition
)
SELECT
    b.user_id,
    b.created_at,
    b.matching_features,
    b.prev_matching_features,
    b.meets_bot_definition,
    b.prev_meets_bot_definition
FROM SUNO_PROD.PROD.BOT_HOURLY b
LEFT JOIN SUNO_PROD.PROD.BOT_STATUS_CHANGES c
ON b.user_id = c.user_id
AND b.created_at = c.status_changed_at
WHERE b.status_changed
-- this allows the job to run idempotently
AND c.user_id IS NULL;
