-- Step 1: Add account_number column to units (rename from buildium_account_number) ALTER TABLE public.units RENAME COLUMN buildium_account_number TO account_number; -- Step 2: Migrate any account_number data from owners to their linked units (if unit doesn't already have one) UPDATE public.units u SET account_number = o.account_number FROM public.owners o WHERE o.unit_id = u.id AND o.account_number IS NOT NULL AND (u.account_number IS NULL OR u.account_number = ''); -- Step 3: Drop account_number from owners ALTER TABLE public.owners DROP COLUMN account_number;