Files
acmcc/supabase/migrations/20260320205815_e97603d5-d1b5-4a61-a3ee-c909d2400b08.sql
2026-06-01 20:19:26 -04:00

15 lines
576 B
SQL

-- 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;