From: Mike Rylander Date: Tue, 15 Nov 2011 21:22:08 +0000 (-0500) Subject: Stamped upgrade for full circ count view fix X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b10df430e2afc97012bb4749b2b05226876db2db;p=contrib%2FConifer.git Stamped upgrade for full circ count view fix 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 db5e247f06..51ab5bc8f9 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -86,7 +86,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 ('0648', :eg_version); -- phasefx/miker +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0649', :eg_version); -- dbwells/tsbere/miker CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0649.schema.fix_full_circ_count_view.sql b/Open-ILS/src/sql/Pg/upgrade/0649.schema.fix_full_circ_count_view.sql new file mode 100644 index 0000000000..2771e8e04b --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0649.schema.fix_full_circ_count_view.sql @@ -0,0 +1,21 @@ +-- Evergreen DB patch 0649.schema.fix_full_circ_count_view.sql +-- +-- FIXME: insert description of change, if needed +-- +BEGIN; + + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('0649', :eg_version); + +-- FIXME: add/check SQL statements to perform the upgrade +CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS + SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(DISTINCT circ.id), 0::bigint) + COALESCE(count(DISTINCT acirc.id), 0::bigint) AS circ_count + FROM asset."copy" cp + LEFT JOIN extend_reporter.legacy_circ_count c USING (id) + LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id + LEFT JOIN "action".aged_circulation acirc ON acirc.target_copy = cp.id + GROUP BY cp.id, c.circ_count; + + +COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql deleted file mode 100644 index 2107adc250..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS - SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(DISTINCT circ.id), 0::bigint) + COALESCE(count(DISTINCT acirc.id), 0::bigint) AS circ_count - FROM asset."copy" cp - LEFT JOIN extend_reporter.legacy_circ_count c USING (id) - LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id - LEFT JOIN "action".aged_circulation acirc ON acirc.target_copy = cp.id - GROUP BY cp.id, c.circ_count;