I also found their is something wrong with my view extend_reporter.all_circulation. I may have carried over a bug that was identified already (but can't find the reference). I have also since added code to archive the copy stat cat. This is also important for our member libraries who will assign a temporary stat cat for course reserves. The code is updated as follows and I have removed the "all_circulation" view until I can fix the code.
BEGIN;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
CREATE TABLE extend_reporter.aged_patron_stat_cats (
id bigserial NOT NULL,
aged_circ_id bigint NOT NULL,
stat_cat text NOT NULL,
stat_cat_entry text NOT NULL
);
ALTER TABLE ONLY extend_reporter.aged_patron_stat_cats
ADD CONSTRAINT aged_patron_stat_cats_pkey PRIMARY KEY (id);
CREATE TABLE extend_reporter.aged_copy_stat_cats (
id bigserial NOT NULL,
aged_circ_id bigint NOT NULL,
stat_cat text NOT NULL,
stat_cat_entry text NOT NULL
);
ALTER TABLE ONLY extend_reporter.aged_copy_stat_cats
ADD CONSTRAINT aged_copy_stat_cats_pkey PRIMARY KEY (id);
CREATE OR REPLACE VIEW extend_reporter.circulation_patron_stat_cats AS
SELECT c.id, s.name, m.stat_cat_entry
FROM action.circulation c JOIN (actor.stat_cat_entry_usr_map m JOIN actor.stat_cat s ON m.stat_cat = s.id) ON c.usr = m.target_usr
UNION ALL
SELECT aged_circ_id, stat_cat, stat_cat_entry FROM extend_reporter.aged_patron_stat_cats;
CREATE OR REPLACE VIEW extend_reporter.circulation_copy_stat_cats AS
SELECT c.id, s.name as stat_cat, e.value as stat_cat_entry
FROM action.circulation c JOIN (asset.stat_cat_entry_copy_map m JOIN (asset.stat_cat s JOIN asset.stat_cat_entry e ON s.id=e.stat_cat) ON m.stat_cat = s.id ) ON c.target_copy = m.owning_copy
UNION ALL
SELECT aged_circ_id, stat_cat, stat_cat_entry FROM extend_reporter.aged_copy_stat_cats;
CREATE OR REPLACE FUNCTION extend_reporter.age_circ_stat_cat_on_delete () RETURNS TRIGGER AS $$
DECLARE
found char := 'N';
BEGIN
-- If there are any renewals for this circulation, don't archive or delete
-- it yet. We'll do so later, when we archive and delete the renewals.
SELECT 'Y' INTO found
FROM action.circulation
WHERE parent_circ = OLD.id
LIMIT 1;
IF found = 'Y' THEN
RETURN NULL; -- don't delete
END IF;
-- Archive a copy of the old row to extend_reporter.aged_stat_cats
INSERT INTO extend_reporter.aged_copy_stat_cats
(aged_circ_id, stat_cat, stat_cat_entry)
SELECT id, stat_cat, stat_cat_entry
FROM extend_reporter.circulation_copy_stat_cats WHERE id = OLD.id;
INSERT INTO extend_reporter.aged_patron_stat_cats
(aged_circ_id, stat_cat, stat_cat_entry)
SELECT id, name, stat_cat_entry
FROM extend_reporter.circulation_patron_stat_cats WHERE id = OLD.id;
RETURN OLD;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER action_circulation_aging_stat_cat_tgr
BEFORE DELETE ON action.circulation
FOR EACH ROW
EXECUTE PROCEDURE extend_reporter.age_circ_stat_cat_on_delete ();
I also found their is something wrong with my view extend_ reporter. all_circulation . I may have carried over a bug that was identified already (but can't find the reference). I have also since added code to archive the copy stat cat. This is also important for our member libraries who will assign a temporary stat cat for course reserves. The code is updated as follows and I have removed the "all_circulation" view until I can fix the code.
BEGIN;
SET client_encoding = 'UTF8'; conforming_ strings = off; bodies = false; string_ warning = off;
SET standard_
SET check_function_
SET client_min_messages = warning;
SET escape_
CREATE TABLE extend_ reporter. aged_patron_ stat_cats (
id bigserial NOT NULL,
aged_circ_id bigint NOT NULL,
stat_cat text NOT NULL,
stat_cat_entry text NOT NULL
);
ALTER TABLE ONLY extend_ reporter. aged_patron_ stat_cats stat_cats_ pkey PRIMARY KEY (id);
ADD CONSTRAINT aged_patron_
CREATE TABLE extend_ reporter. aged_copy_ stat_cats (
id bigserial NOT NULL,
aged_circ_id bigint NOT NULL,
stat_cat text NOT NULL,
stat_cat_entry text NOT NULL
);
ALTER TABLE ONLY extend_ reporter. aged_copy_ stat_cats stat_cats_ pkey PRIMARY KEY (id);
ADD CONSTRAINT aged_copy_
CREATE OR REPLACE VIEW extend_ reporter. circulation_ patron_ stat_cats AS stat_cat_ entry_usr_ map m JOIN actor.stat_cat s ON m.stat_cat = s.id) ON c.usr = m.target_usr reporter. aged_patron_ stat_cats;
SELECT c.id, s.name, m.stat_cat_entry
FROM action.circulation c JOIN (actor.
UNION ALL
SELECT aged_circ_id, stat_cat, stat_cat_entry FROM extend_
CREATE OR REPLACE VIEW extend_ reporter. circulation_ copy_stat_ cats AS stat_cat_ entry_copy_ map m JOIN (asset.stat_cat s JOIN asset.stat_ cat_entry e ON s.id=e.stat_cat) ON m.stat_cat = s.id ) ON c.target_copy = m.owning_copy reporter. aged_copy_ stat_cats;
SELECT c.id, s.name as stat_cat, e.value as stat_cat_entry
FROM action.circulation c JOIN (asset.
UNION ALL
SELECT aged_circ_id, stat_cat, stat_cat_entry FROM extend_
CREATE OR REPLACE FUNCTION extend_ reporter. age_circ_ stat_cat_ on_delete () RETURNS TRIGGER AS $$
DECLARE
found char := 'N';
BEGIN
-- If there are any renewals for this circulation, don't archive or delete
-- it yet. We'll do so later, when we archive and delete the renewals.
SELECT 'Y' INTO found
FROM action.circulation
WHERE parent_circ = OLD.id
LIMIT 1;
IF found = 'Y' THEN
RETURN NULL; -- don't delete
END IF;
-- Archive a copy of the old row to extend_ reporter. aged_stat_ cats reporter. aged_copy_ stat_cats reporter. circulation_ copy_stat_ cats WHERE id = OLD.id;
INSERT INTO extend_
(aged_circ_id, stat_cat, stat_cat_entry)
SELECT id, stat_cat, stat_cat_entry
FROM extend_
INSERT INTO extend_ reporter. aged_patron_ stat_cats reporter. circulation_ patron_ stat_cats WHERE id = OLD.id;
(aged_circ_id, stat_cat, stat_cat_entry)
SELECT id, name, stat_cat_entry
FROM extend_
RETURN OLD;
END;
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER action_ circulation_ aging_stat_ cat_tgr reporter. age_circ_ stat_cat_ on_delete ();
BEFORE DELETE ON action.circulation
FOR EACH ROW
EXECUTE PROCEDURE extend_
END