ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED
);
-CREATE TRIGGER action_usr_circ_history_target_copy_trig
- AFTER INSERT OR UPDATE ON action.usr_circ_history
- FOR EACH ROW EXECUTE PROCEDURE evergreen.fake_fkey_tgr('target_copy');
-
-CREATE INDEX action_usr_circ_history_usr_idx ON action.usr_circ_history (usr);
CREATE OR REPLACE FUNCTION action.maintain_usr_circ_history()
RETURNS TRIGGER AS $FUNK$
END;
$FUNK$ LANGUAGE PLPGSQL;
+-- Create TRIGGER after migration
CREATE TRIGGER maintain_usr_circ_history_tgr
AFTER INSERT OR UPDATE ON action.circulation
FOR EACH ROW EXECUTE PROCEDURE action.maintain_usr_circ_history();
-- no modifications are required.
-- Create circ history rows for existing circ history data.
-DO $FUNK$
+CREATE OR REPLACE FUNCTION action.migrate_usr_circ_history
+ (mod_factor INT, mod_slot INT) RETURNS VOID AS $FUNK$
DECLARE
cur_usr INTEGER;
cur_circ action.circulation%ROWTYPE;
last_circ action.circulation%ROWTYPE;
- counter INTEGER DEFAULT 1;
+ circ_counter INTEGER DEFAULT 1;
+ usr_counter INTEGER DEFAULT 1;
BEGIN
RAISE NOTICE
'Migrating circ history for % users. This might take a while...',
(SELECT COUNT(DISTINCT(au.id)) FROM actor.usr au
JOIN actor.usr_setting aus ON (aus.usr = au.id)
- WHERE NOT au.deleted AND
- aus.name ~ '^history.circ.retention_');
+ WHERE
+ NOT au.deleted
+ AND aus.name ~ '^history.circ.retention_'
+ AND (au.id % mod_factor) = mod_slot);
FOR cur_usr IN
SELECT DISTINCT(au.id)
FROM actor.usr au
JOIN actor.usr_setting aus ON (aus.usr = au.id)
- WHERE NOT au.deleted AND
- aus.name ~ '^history.circ.retention_' LOOP
+ WHERE
+ NOT au.deleted
+ AND aus.name ~ '^history.circ.retention_'
+ AND (au.id % mod_factor) = mod_slot LOOP
FOR cur_circ IN SELECT * FROM action.usr_visible_circs(cur_usr) LOOP
);
-- useful for alleviating administrator anxiety.
- IF counter % 10000 = 0 THEN
- RAISE NOTICE 'Migrated history for % total users', counter;
+ IF circ_counter % 10000 = 0 THEN
+ RAISE NOTICE 'Migrated history for % total circs', circ_counter;
END IF;
- counter := counter + 1;
+ circ_counter := circ_counter + 1;
END LOOP;
+
+ -- useful for alleviating administrator anxiety.
+ IF usr_counter % 1000 = 0 THEN
+ RAISE NOTICE 'Migrated history for % total users', usr_counter;
+ END IF;
+
+ usr_counter := usr_counter + 1;
+
END LOOP;
-END $FUNK$;
+END $FUNK$ LANGUAGE PLPGSQL;
-DROP FUNCTION IF EXISTS action.usr_visible_circs (INTEGER);
-DROP FUNCTION IF EXISTS action.usr_visible_circ_copies (INTEGER);
CREATE OR REPLACE FUNCTION action.purge_circulations_custom () RETURNS INT AS $func$
DECLARE
$$ LANGUAGE plpgsql;
COMMIT;
+
+-- APPLY THESE POST-MIGRATION
+
+/*
+
+CREATE TRIGGER action_usr_circ_history_target_copy_trig
+ AFTER INSERT OR UPDATE ON action.usr_circ_history
+ FOR EACH ROW EXECUTE PROCEDURE evergreen.fake_fkey_tgr('target_copy');
+
+
+DROP FUNCTION IF EXISTS action.usr_visible_circs (INTEGER);
+DROP FUNCTION IF EXISTS action.usr_visible_circ_copies (INTEGER);
+
+CREATE INDEX action_usr_circ_history_usr_idx ON action.usr_circ_history (usr);
+
+*/
+