diff --git a/supabase/migrations/20260419225947_8d9ead74-700d-417e-b6f2-bfcbbe9799cb.sql b/supabase/migrations/20260419225947_8d9ead74-700d-417e-b6f2-bfcbbe9799cb.sql new file mode 100644 index 0000000..ec4b9ea --- /dev/null +++ b/supabase/migrations/20260419225947_8d9ead74-700d-417e-b6f2-bfcbbe9799cb.sql @@ -0,0 +1,18 @@ +-- Delete the 7,953 placeholder clients created by the bad invoice import. +-- These are archived, have numeric external_id (e.g. "10008057"), and have +-- no linked cases, invoices, homeowners, contacts, or field values. +DELETE FROM public.client_field_values + WHERE client_id IN ( + SELECT id FROM public.clients + WHERE archived_at IS NOT NULL AND external_id ~ '^[0-9]+$' + ); + +DELETE FROM public.client_contacts + WHERE client_id IN ( + SELECT id FROM public.clients + WHERE archived_at IS NOT NULL AND external_id ~ '^[0-9]+$' + ); + +DELETE FROM public.clients + WHERE archived_at IS NOT NULL + AND external_id ~ '^[0-9]+$'; \ No newline at end of file