ALTER TABLE public.budgets
  ADD COLUMN IF NOT EXISTS parent_id UUID REFERENCES public.budgets(id) ON DELETE CASCADE,
  ADD COLUMN IF NOT EXISTS account_type TEXT NOT NULL DEFAULT 'expense',
  ADD COLUMN IF NOT EXISTS is_parent BOOLEAN NOT NULL DEFAULT false;

ALTER TABLE public.budgets ALTER COLUMN budgeted_amount DROP NOT NULL;
ALTER TABLE public.budgets ALTER COLUMN budgeted_amount SET DEFAULT 0;

CREATE INDEX IF NOT EXISTS idx_budgets_parent_id ON public.budgets(parent_id);
CREATE INDEX IF NOT EXISTS idx_budgets_assoc_year ON public.budgets(association_id, fiscal_year);