Files
acmcc/supabase/migrations/20260319000555_c1f7c767-3d2b-44ea-bdb4-5f75939f0fae.sql
T
2026-06-01 20:19:26 -04:00

11 lines
614 B
SQL

-- Add a unique constraint on owners for Buildium sync upserts
-- Using association_id + first_name + last_name + property_address to handle multiple owners at same address
CREATE UNIQUE INDEX IF NOT EXISTS owners_buildium_sync_key
ON public.owners (association_id, first_name, last_name, property_address)
WHERE property_address IS NOT NULL;
-- Add buildium_owner_id column for future direct ID mapping
ALTER TABLE public.owners ADD COLUMN IF NOT EXISTS buildium_owner_id text;
CREATE UNIQUE INDEX IF NOT EXISTS owners_buildium_id_key ON public.owners (buildium_owner_id) WHERE buildium_owner_id IS NOT NULL;