ALTER TABLE public.vendors ADD COLUMN IF NOT EXISTS association_ids uuid[] NOT NULL DEFAULT ARRAY[]::uuid[];

-- Backfill: ensure existing single association_id is included in the array
UPDATE public.vendors
SET association_ids = ARRAY[association_id]
WHERE association_id IS NOT NULL
  AND (association_ids IS NULL OR NOT (association_id = ANY(association_ids)));

-- Index for fast filtering
CREATE INDEX IF NOT EXISTS idx_vendors_association_ids ON public.vendors USING GIN (association_ids);