--- /dev/null
+BEGIN;
+
+INSERT INTO acq.invoice (id, receiver, provider, shipper, recv_method, inv_ident, closed_by)
+ VALUES (2222, 1, 1, 1, 'EDI', 'ABC123', 10);
+
+INSERT INTO action.curbside (id, patron, org, notes)
+ VALUES (2222, 10, 1, 'Private info');
+
+INSERT INTO actor.usr_message (usr, message, sending_lib)
+ VALUES (10, 'Private message', 1);
+
+SELECT plan(3);
+
+SELECT * FROM actor.usr_purge_data(10, 20);
+
+SELECT is(
+ (SELECT closed_by FROM acq.invoice WHERE id = 2222)::INTEGER,
+ 20::INTEGER,
+ 'Acq invoice is now owned by dest_usr'
+);
+
+SELECT is(
+ (SELECT notes FROM action.curbside WHERE id = 2222),
+ NULL,
+ 'Curbside notes are redacted'
+);
+
+SELECT is_empty(
+ ('SELECT id FROM actor.usr_message WHERE usr=10 AND NOT deleted'),
+ 'User messages are marked as deleted'
+);
+
+SELECT * FROM finish();
+ROLLBACK;
\ No newline at end of file
BEGIN;
-SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version);
CREATE OR REPLACE FUNCTION actor.usr_purge_data(
src_usr IN INTEGER,
dest_usr := specified_dest_usr;
END IF;
+ -- action_trigger.event (even doing this, event_output may--and probably does--contain PII and should have a retention/removal policy)
+ UPDATE action_trigger.event SET context_user = dest_usr WHERE context_user = src_usr;
+
-- acq.*
UPDATE acq.fund_allocation SET allocator = dest_usr WHERE allocator = src_usr;
UPDATE acq.lineitem SET creator = dest_usr WHERE creator = src_usr;
UPDATE actor.usr_address SET replaces = NULL
WHERE usr = src_usr AND replaces IS NOT NULL;
DELETE FROM actor.usr_address WHERE usr = src_usr;
- DELETE FROM actor.usr_note WHERE usr = src_usr;
- UPDATE actor.usr_note SET creator = dest_usr WHERE creator = src_usr;
DELETE FROM actor.usr_org_unit_opt_in WHERE usr = src_usr;
UPDATE actor.usr_org_unit_opt_in SET staff = dest_usr WHERE staff = src_usr;
DELETE FROM actor.usr_setting WHERE usr = src_usr;
DELETE FROM actor.usr_standing_penalty WHERE usr = src_usr;
+ UPDATE actor.usr_message SET title = 'purged', message = 'purged', read_date = NOW() WHERE usr = src_usr;
+ DELETE FROM actor.usr_message WHERE usr = src_usr;
UPDATE actor.usr_standing_penalty SET staff = dest_usr WHERE staff = src_usr;
+ UPDATE actor.usr_message SET editor = dest_usr WHERE editor = src_usr;
-- asset.*
UPDATE asset.call_number SET creator = dest_usr WHERE creator = src_usr;