2 * Copyright (C) 2008 Equinox Software, Inc.
3 * Mike Rylander <miker@esilibrary.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 DROP SCHEMA IF EXISTS extend_reporter CASCADE;
21 CREATE SCHEMA extend_reporter;
23 CREATE TABLE extend_reporter.legacy_circ_count (
24 id BIGINT PRIMARY KEY, -- REFERENCES asset.copy (id) DEFERRABLE INITIALLY DEFERRED, -- XXX could be an serial.issuance
25 circ_count INT NOT NULL DEFAULT 0
28 CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS
30 COALESCE((SELECT circ_count FROM extend_reporter.legacy_circ_count WHERE id = cp.id), 0)
31 + (SELECT COUNT(*) FROM action.circulation WHERE target_copy = cp.id)
32 + (SELECT COUNT(*) FROM action.aged_circulation WHERE target_copy = cp.id) AS circ_count
35 CREATE OR REPLACE VIEW extend_reporter.global_bibs_by_holding_update AS
36 SELECT DISTINCT ON (id) id, holding_update, update_type
38 LAST(cp.create_date) AS holding_update,
40 FROM biblio.record_entry b
41 JOIN asset.call_number cn ON (cn.record = b.id)
42 JOIN asset.copy cp ON (cp.call_number = cn.id)
48 LAST(cp.edit_date) AS holding_update,
49 'delete' AS update_type
50 FROM biblio.record_entry b
51 JOIN asset.call_number cn ON (cn.record = b.id)
52 JOIN asset.copy cp ON (cp.call_number = cn.id)
56 ORDER BY id, holding_update;