ALTER TABLE sessions
    ADD COLUMN confirmation_sent_at TIMESTAMPTZ;

-- Update existing ConfirmationSent sessions to have a sentinel value
-- so they don't get re-processed after migration
UPDATE sessions
SET confirmation_sent_at = now()
WHERE status = 'ConfirmationSent';

-- Partial index for efficient T-24h query
CREATE INDEX ix_sessions_confirmation_reminders ON sessions (scheduled_at)
    WHERE status = 'Planned'
      AND confirmation_sent_at IS NULL;
