From d02c79b00891629241b27397c34c3c910897f745 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 15 Aug 2017 10:21:36 -0400 Subject: [PATCH] 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 --- .../schema/tools/circ-history-delete-untracked.sql | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 KCLS/sql/schema/tools/circ-history-delete-untracked.sql 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; + -- 2.11.0