-- Active/inactive agent roster. Legacy's `state.agents[].active` flag
-- controls who gets scored/ranked/scheduled (`renderAgents`'s own page
-- subtitle: "Only active agents are scored and ranked"). This project
-- has no separate `agents` table (profiles + agent_id is the closest
-- equivalent), so the flag lands on profiles directly.
--
-- Defaults true so every existing profile stays exactly as visible as
-- it is today — this migration only adds the capability to turn
-- someone off, it doesn't change anyone's current status.
--
-- The actual "removes them from schedule/ranking/performance lists"
-- behavior comes from filtering is_active=true in /api/agent-roster and
-- /api/team-standings (both updated in the same commit as this
-- migration) — every page that lists agents already sources its roster
-- from one of those two routes, so this column alone does nothing until
-- those routes filter on it.

alter table public.profiles
  add column if not exists is_active boolean not null default true;

do $migration_guard$
declare
  col_exists boolean;
begin
  select exists (
    select 1 from information_schema.columns
    where table_schema = 'public' and table_name = 'profiles' and column_name = 'is_active'
  ) into col_exists;
  if not col_exists then
    raise exception 'Aborting 0029: profiles.is_active column was not created';
  end if;
end $migration_guard$;
