From: Bill Erickson Date: Tue, 15 Aug 2017 14:21:36 +0000 (-0400) Subject: JBAS-1554 Circ history delete untracked X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d02c79b00891629241b27397c34c3c910897f745;p=working%2FEvergreen.git JBAS-1554 Circ history delete untracked Script to find and delete circulation history rows for patrons who disabled circ history after the initial migration but before the new history delete code was deployed. Signed-off-by: Bill Erickson --- diff --git a/KCLS/sql/schema/tools/circ-history-delete-untracked.sql b/KCLS/sql/schema/tools/circ-history-delete-untracked.sql new file mode 100644 index 0000000000..6123346a36 --- /dev/null +++ b/KCLS/sql/schema/tools/circ-history-delete-untracked.sql @@ -0,0 +1,24 @@ +/** + * Delete circ history rows for patrons who disabled circ history + * tracking between the initial migration and when the updated + * circ history code was deployed. + */ + +BEGIN; + +SET STATEMENT_TIMEOUT = 0; + +WITH delete_history_usrs AS ( + SELECT DISTINCT(auch.usr) AS usr_id + FROM action.usr_circ_history auch + WHERE NOT EXISTS( + SELECT TRUE FROM actor.usr_setting set + WHERE set.usr = auch.usr + AND set.name ~ '^history.circ.retention_' + ) +) DELETE FROM action.usr_circ_history + WHERE usr IN (SELECT usr_id FROM delete_history_usrs); + +--ROLLBACK; +COMMIT; +