-- Run once in Supabase if leave applications fail with "validate leave quota" / missing leave_category.

alter table public.leave_applications
  add column if not exists leave_category text;

update public.leave_applications
set leave_category = 'casual'
where leave_category is null or leave_category = '';

update public.leave_applications
set leave_category = 'casual'
where leave_category not in ('sick', 'casual');

alter table public.leave_applications
  alter column leave_category set default 'casual';

alter table public.leave_applications
  alter column leave_category set not null;

alter table public.leave_applications
  drop constraint if exists leave_applications_category_check;

alter table public.leave_applications
  add constraint leave_applications_category_check
  check (leave_category in ('sick', 'casual'));
