3 SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version);
5 CREATE OR REPLACE FUNCTION actor.usr_purge_data(
7 specified_dest_usr IN INTEGER
15 IF specified_dest_usr IS NULL THEN
16 dest_usr := 1; -- Admin user on stock installs
18 dest_usr := specified_dest_usr;
22 UPDATE acq.fund_allocation SET allocator = dest_usr WHERE allocator = src_usr;
23 UPDATE acq.lineitem SET creator = dest_usr WHERE creator = src_usr;
24 UPDATE acq.lineitem SET editor = dest_usr WHERE editor = src_usr;
25 UPDATE acq.lineitem SET selector = dest_usr WHERE selector = src_usr;
26 UPDATE acq.lineitem_note SET creator = dest_usr WHERE creator = src_usr;
27 UPDATE acq.lineitem_note SET editor = dest_usr WHERE editor = src_usr;
28 UPDATE acq.invoice SET closed_by = dest_usr WHERE closed_by = src_usr;
29 DELETE FROM acq.lineitem_usr_attr_definition WHERE usr = src_usr;
31 -- Update with a rename to avoid collisions
37 suffix := ' (' || src_usr || ')';
41 SET owner = dest_usr, name = name || suffix
42 WHERE id = renamable_row.id;
43 EXCEPTION WHEN unique_violation THEN
44 suffix := suffix || ' ';
51 UPDATE acq.picklist SET creator = dest_usr WHERE creator = src_usr;
52 UPDATE acq.picklist SET editor = dest_usr WHERE editor = src_usr;
53 UPDATE acq.po_note SET creator = dest_usr WHERE creator = src_usr;
54 UPDATE acq.po_note SET editor = dest_usr WHERE editor = src_usr;
55 UPDATE acq.purchase_order SET owner = dest_usr WHERE owner = src_usr;
56 UPDATE acq.purchase_order SET creator = dest_usr WHERE creator = src_usr;
57 UPDATE acq.purchase_order SET editor = dest_usr WHERE editor = src_usr;
58 UPDATE acq.claim_event SET creator = dest_usr WHERE creator = src_usr;
61 DELETE FROM action.circulation WHERE usr = src_usr;
62 UPDATE action.circulation SET circ_staff = dest_usr WHERE circ_staff = src_usr;
63 UPDATE action.circulation SET checkin_staff = dest_usr WHERE checkin_staff = src_usr;
64 UPDATE action.hold_notification SET notify_staff = dest_usr WHERE notify_staff = src_usr;
65 UPDATE action.hold_request SET fulfillment_staff = dest_usr WHERE fulfillment_staff = src_usr;
66 UPDATE action.hold_request SET requestor = dest_usr WHERE requestor = src_usr;
67 DELETE FROM action.hold_request WHERE usr = src_usr;
68 UPDATE action.in_house_use SET staff = dest_usr WHERE staff = src_usr;
69 UPDATE action.non_cat_in_house_use SET staff = dest_usr WHERE staff = src_usr;
70 DELETE FROM action.non_cataloged_circulation WHERE patron = src_usr;
71 UPDATE action.non_cataloged_circulation SET staff = dest_usr WHERE staff = src_usr;
72 DELETE FROM action.survey_response WHERE usr = src_usr;
73 UPDATE action.fieldset SET owner = dest_usr WHERE owner = src_usr;
74 DELETE FROM action.usr_circ_history WHERE usr = src_usr;
75 UPDATE action.curbside SET notes = NULL WHERE patron = src_usr;
78 DELETE FROM actor.card WHERE usr = src_usr;
79 DELETE FROM actor.stat_cat_entry_usr_map WHERE target_usr = src_usr;
80 DELETE FROM actor.usr_privacy_waiver WHERE usr = src_usr;
81 DELETE FROM actor.usr_message WHERE usr = src_usr;
83 -- The following update is intended to avoid transient violations of a foreign
84 -- key constraint, whereby actor.usr_address references itself. It may not be
85 -- necessary, but it does no harm.
86 UPDATE actor.usr_address SET replaces = NULL
87 WHERE usr = src_usr AND replaces IS NOT NULL;
88 DELETE FROM actor.usr_address WHERE usr = src_usr;
89 DELETE FROM actor.usr_note WHERE usr = src_usr;
90 UPDATE actor.usr_note SET creator = dest_usr WHERE creator = src_usr;
91 DELETE FROM actor.usr_org_unit_opt_in WHERE usr = src_usr;
92 UPDATE actor.usr_org_unit_opt_in SET staff = dest_usr WHERE staff = src_usr;
93 DELETE FROM actor.usr_setting WHERE usr = src_usr;
94 DELETE FROM actor.usr_standing_penalty WHERE usr = src_usr;
95 UPDATE actor.usr_standing_penalty SET staff = dest_usr WHERE staff = src_usr;
98 UPDATE asset.call_number SET creator = dest_usr WHERE creator = src_usr;
99 UPDATE asset.call_number SET editor = dest_usr WHERE editor = src_usr;
100 UPDATE asset.call_number_note SET creator = dest_usr WHERE creator = src_usr;
101 UPDATE asset.copy SET creator = dest_usr WHERE creator = src_usr;
102 UPDATE asset.copy SET editor = dest_usr WHERE editor = src_usr;
103 UPDATE asset.copy_note SET creator = dest_usr WHERE creator = src_usr;
106 DELETE FROM auditor.actor_usr_address_history WHERE id = src_usr;
107 DELETE FROM auditor.actor_usr_history WHERE id = src_usr;
108 UPDATE auditor.asset_call_number_history SET creator = dest_usr WHERE creator = src_usr;
109 UPDATE auditor.asset_call_number_history SET editor = dest_usr WHERE editor = src_usr;
110 UPDATE auditor.asset_copy_history SET creator = dest_usr WHERE creator = src_usr;
111 UPDATE auditor.asset_copy_history SET editor = dest_usr WHERE editor = src_usr;
112 UPDATE auditor.biblio_record_entry_history SET creator = dest_usr WHERE creator = src_usr;
113 UPDATE auditor.biblio_record_entry_history SET editor = dest_usr WHERE editor = src_usr;
116 UPDATE biblio.record_entry SET creator = dest_usr WHERE creator = src_usr;
117 UPDATE biblio.record_entry SET editor = dest_usr WHERE editor = src_usr;
118 UPDATE biblio.record_note SET creator = dest_usr WHERE creator = src_usr;
119 UPDATE biblio.record_note SET editor = dest_usr WHERE editor = src_usr;
122 -- Update buckets with a rename to avoid collisions
125 FROM container.biblio_record_entry_bucket
126 WHERE owner = src_usr
128 suffix := ' (' || src_usr || ')';
131 UPDATE container.biblio_record_entry_bucket
132 SET owner = dest_usr, name = name || suffix
133 WHERE id = renamable_row.id;
134 EXCEPTION WHEN unique_violation THEN
135 suffix := suffix || ' ';
144 FROM container.call_number_bucket
145 WHERE owner = src_usr
147 suffix := ' (' || src_usr || ')';
150 UPDATE container.call_number_bucket
151 SET owner = dest_usr, name = name || suffix
152 WHERE id = renamable_row.id;
153 EXCEPTION WHEN unique_violation THEN
154 suffix := suffix || ' ';
163 FROM container.copy_bucket
164 WHERE owner = src_usr
166 suffix := ' (' || src_usr || ')';
169 UPDATE container.copy_bucket
170 SET owner = dest_usr, name = name || suffix
171 WHERE id = renamable_row.id;
172 EXCEPTION WHEN unique_violation THEN
173 suffix := suffix || ' ';
182 FROM container.user_bucket
183 WHERE owner = src_usr
185 suffix := ' (' || src_usr || ')';
188 UPDATE container.user_bucket
189 SET owner = dest_usr, name = name || suffix
190 WHERE id = renamable_row.id;
191 EXCEPTION WHEN unique_violation THEN
192 suffix := suffix || ' ';
199 DELETE FROM container.user_bucket_item WHERE target_user = src_usr;
202 DELETE FROM money.billable_xact WHERE usr = src_usr;
203 DELETE FROM money.collections_tracker WHERE usr = src_usr;
204 UPDATE money.collections_tracker SET collector = dest_usr WHERE collector = src_usr;
207 DELETE FROM permission.usr_grp_map WHERE usr = src_usr;
208 DELETE FROM permission.usr_object_perm_map WHERE usr = src_usr;
209 DELETE FROM permission.usr_perm_map WHERE usr = src_usr;
210 DELETE FROM permission.usr_work_ou_map WHERE usr = src_usr;
213 -- Update with a rename to avoid collisions
217 FROM reporter.output_folder
218 WHERE owner = src_usr
220 suffix := ' (' || src_usr || ')';
223 UPDATE reporter.output_folder
224 SET owner = dest_usr, name = name || suffix
225 WHERE id = renamable_row.id;
226 EXCEPTION WHEN unique_violation THEN
227 suffix := suffix || ' ';
233 EXCEPTION WHEN undefined_table THEN
238 UPDATE reporter.report SET owner = dest_usr WHERE owner = src_usr;
239 EXCEPTION WHEN undefined_table THEN
243 -- Update with a rename to avoid collisions
247 FROM reporter.report_folder
248 WHERE owner = src_usr
250 suffix := ' (' || src_usr || ')';
253 UPDATE reporter.report_folder
254 SET owner = dest_usr, name = name || suffix
255 WHERE id = renamable_row.id;
256 EXCEPTION WHEN unique_violation THEN
257 suffix := suffix || ' ';
263 EXCEPTION WHEN undefined_table THEN
268 UPDATE reporter.schedule SET runner = dest_usr WHERE runner = src_usr;
269 EXCEPTION WHEN undefined_table THEN
274 UPDATE reporter.template SET owner = dest_usr WHERE owner = src_usr;
275 EXCEPTION WHEN undefined_table THEN
279 -- Update with a rename to avoid collisions
283 FROM reporter.template_folder
284 WHERE owner = src_usr
286 suffix := ' (' || src_usr || ')';
289 UPDATE reporter.template_folder
290 SET owner = dest_usr, name = name || suffix
291 WHERE id = renamable_row.id;
292 EXCEPTION WHEN unique_violation THEN
293 suffix := suffix || ' ';
299 EXCEPTION WHEN undefined_table THEN
304 -- Update with a rename to avoid collisions
308 WHERE owner = src_usr
310 suffix := ' (' || src_usr || ')';
313 UPDATE vandelay.queue
314 SET owner = dest_usr, name = name || suffix
315 WHERE id = renamable_row.id;
316 EXCEPTION WHEN unique_violation THEN
317 suffix := suffix || ' ';
324 UPDATE vandelay.session_tracker SET usr = dest_usr WHERE usr = src_usr;
326 -- NULL-ify addresses last so other cleanup (e.g. circ anonymization)
327 -- can access the information before deletion.
331 mailing_address = NULL,
332 billing_address = NULL