picklist_row RECORD;
queue_row RECORD;
folder_row RECORD;
+ src_addr INTEGER;
BEGIN
-- Bail if src_usr equals dest_usr because the result of merging a
UPDATE actor.card SET usr = dest_usr WHERE usr = src_usr;
END IF;
+ -- if addresses are shared then remap them to one of the undeleted accounts
+ FOR src_addr IN SELECT id FROM actor.usr_address WHERE usr = src_usr LOOP
+ UPDATE actor.usr_address SET usr = (SELECT id FROM actor.usr WHERE deleted = FALSE
+ AND mailing_address = src_addr AND id != src_usr LIMIT 1) WHERE usr = src_usr;
+ UPDATE actor.usr_address SET usr = (SELECT id FROM actor.usr WHERE deleted = FALSE
+ AND billing_address = src_addr AND id != src_usr LIMIT 1) WHERE usr = src_usr;
+ END LOOP;
IF del_addrs THEN
DELETE FROM actor.usr_address WHERE usr = src_usr;