#!/bin/bash
# Survey rotation — runs every Monday at midnight ET
# Deactivates all surveys, then activates the one whose week_start matches this week.

export PGPASSWORD=eventheodds_dev_password

psql -h 127.0.0.1 -p 5433 -U eventheodds -d eventheodds_sports <<'SQL'
-- Deactivate all
UPDATE rm_surveys SET is_active = false WHERE is_active = true;

-- Activate the survey for this week (week_start <= today < week_start + 7)
UPDATE rm_surveys
SET is_active = true
WHERE week_start <= (CURRENT_TIMESTAMP AT TIME ZONE 'America/New_York')::date
  AND week_start + 7 > (CURRENT_TIMESTAMP AT TIME ZONE 'America/New_York')::date;

-- Log which survey is now active
SELECT title, week_start, is_active FROM rm_surveys WHERE is_active = true;
SQL
