
-- Drop the unique constraint on (association_id, charge_type) to allow multiple mappings per charge type
ALTER TABLE public.buildium_gl_mappings DROP CONSTRAINT IF EXISTS buildium_gl_mappings_association_id_charge_type_key;

-- Add amount threshold columns
ALTER TABLE public.buildium_gl_mappings
  ADD COLUMN IF NOT EXISTS amount_min numeric DEFAULT NULL,
  ADD COLUMN IF NOT EXISTS amount_max numeric DEFAULT NULL;

-- Add a unique constraint that includes amount thresholds
ALTER TABLE public.buildium_gl_mappings
  ADD CONSTRAINT buildium_gl_mappings_assoc_type_amount_unique
  UNIQUE (association_id, charge_type, amount_min, amount_max);
