-- ================================================
-- Migration: Registration-level activation status rollup
-- Date: 2026-07-14
-- Mirrors the most recently toggled
-- hdb_program_registration_online_session.activation_status onto the owning
-- registration, so admin list views can show "active/inactive" without needing
-- a session context. The per-session extension row remains the source of truth
-- for "active on session X specifically" — this is a rollup, not a replacement.
-- Safe to re-run (IF NOT EXISTS).
-- ================================================

ALTER TABLE hdb_program_registration
  ADD COLUMN IF NOT EXISTS activation_status VARCHAR(20) NOT NULL DEFAULT 'active';

COMMENT ON COLUMN hdb_program_registration.activation_status IS
  'Rollup of this registrant''s activation state across their online sessions — mirrors the most recently toggled hdb_program_registration_online_session.activation_status.';

ALTER TABLE hdb_program_registration
  ADD COLUMN IF NOT EXISTS activation_updated_at TIMESTAMPTZ NULL;

-- Verification
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'hdb_program_registration'
  AND column_name IN ('activation_status', 'activation_updated_at');
