-- Add login table create table if not exists people ( id uuid NOT NULL DEFAULT gen_random_uuid (), created_at timestamp without time zone NOT NULL DEFAULT now(), created_by uuid NOT NULL, updated_at timestamp without time zone NOT NULL DEFAULT now(), updated_by uuid NOT NULL, email text NOT NULL, name text NOT NULL, family_name text NOT NULL, given_name text NOT NULL ); ALTER TABLE people ADD CONSTRAINT people_pkey PRIMARY KEY (id); ALTER TABLE if exists users ADD COLUMN person_id uuid REFERENCES people (id) ON DELETE SET NULL; -- Copy accounts(users) to profiles(people) insert into people (created_by, updated_by, email, name, family_name, given_name) select created_by, updated_by, email, name, family_name, given_name from users; -- Link accounts to profiles update users u set person_id = p.id from people p where p.email = u.email; -- Move wishlist items from accounts to profiles update wishlist_items wi set user_id = p.person_id from users p where p.id = wi.user_id;