From: Mike Rylander Date: Wed, 24 Aug 2016 16:38:58 +0000 (-0400) Subject: Stamping upgrade script for transient usr_activity X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=95ea3d5223963777f8d76d11ab0dd7e4eeeeceff;p=evergreen%2Fmasslnc.git Stamping upgrade script for transient usr_activity Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 0bba11c55e..d7438fb656 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -91,7 +91,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0992', :eg_version); -- berick/miker +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0993', :eg_version); -- berick/miker CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0993.schema.usr_activity_transient.sql b/Open-ILS/src/sql/Pg/upgrade/0993.schema.usr_activity_transient.sql new file mode 100644 index 0000000000..d195004808 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0993.schema.usr_activity_transient.sql @@ -0,0 +1,35 @@ + +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('0993', :eg_version); + +ALTER TABLE config.usr_activity_type + ALTER COLUMN transient SET DEFAULT TRUE; + +-- Utility function for removing all activity entries by activity type, +-- except for the most recent entry per user. This is primarily useful +-- when cleaning up rows prior to setting the transient flag on an +-- activity type to true. It allows for immediate cleanup of data (e.g. +-- for patron privacy) and lets admins control when the data is deleted, +-- which could be useful for huge activity tables. + +CREATE OR REPLACE FUNCTION + actor.purge_usr_activity_by_type(act_type INTEGER) + RETURNS VOID AS $$ +DECLARE + cur_usr INTEGER; +BEGIN + FOR cur_usr IN SELECT DISTINCT(usr) + FROM actor.usr_activity WHERE etype = act_type LOOP + DELETE FROM actor.usr_activity WHERE id IN ( + SELECT id + FROM actor.usr_activity + WHERE usr = cur_usr AND etype = act_type + ORDER BY event_time DESC OFFSET 1 + ); + + END LOOP; +END $$ LANGUAGE PLPGSQL; + +COMMIT; + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.usr_activity_transient.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.usr_activity_transient.sql deleted file mode 100644 index fb70a87141..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.usr_activity_transient.sql +++ /dev/null @@ -1,35 +0,0 @@ - -BEGIN; - -SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); - -ALTER TABLE config.usr_activity_type - ALTER COLUMN transient SET DEFAULT TRUE; - --- Utility function for removing all activity entries by activity type, --- except for the most recent entry per user. This is primarily useful --- when cleaning up rows prior to setting the transient flag on an --- activity type to true. It allows for immediate cleanup of data (e.g. --- for patron privacy) and lets admins control when the data is deleted, --- which could be useful for huge activity tables. - -CREATE OR REPLACE FUNCTION - actor.purge_usr_activity_by_type(act_type INTEGER) - RETURNS VOID AS $$ -DECLARE - cur_usr INTEGER; -BEGIN - FOR cur_usr IN SELECT DISTINCT(usr) - FROM actor.usr_activity WHERE etype = act_type LOOP - DELETE FROM actor.usr_activity WHERE id IN ( - SELECT id - FROM actor.usr_activity - WHERE usr = cur_usr AND etype = act_type - ORDER BY event_time DESC OFFSET 1 - ); - - END LOOP; -END $$ LANGUAGE PLPGSQL; - -COMMIT; -