DROP INDEX IF EXISTS public.owner_ledger_entries_buildium_reference_unique;

CREATE UNIQUE INDEX IF NOT EXISTS owner_ledger_entries_buildium_reference_unique
ON public.owner_ledger_entries (owner_id, reference_id)
WHERE reference_type = 'buildium' AND reference_id IS NOT NULL;