
-- Add association_ids array column to chart_of_accounts
ALTER TABLE public.chart_of_accounts ADD COLUMN association_ids UUID[] DEFAULT '{}';

-- Migrate existing association_id values into the array
UPDATE public.chart_of_accounts 
SET association_ids = ARRAY[association_id]
WHERE association_id IS NOT NULL AND (association_ids IS NULL OR association_ids = '{}');

-- Create index for array containment queries
CREATE INDEX idx_chart_of_accounts_association_ids ON public.chart_of_accounts USING GIN (association_ids);
