]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/extend-reporter.sql
add a reasonable prefix to autogenerated TCNs
[Evergreen.git] / Open-ILS / src / sql / Pg / extend-reporter.sql
1 /*
2  * Copyright (C) 2008  Equinox Software, Inc.
3  * Mike Rylander <miker@esilibrary.com> 
4  *
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.
9  *
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.
14  *
15  */
16
17 DROP SCHEMA extend_reporter CASCADE;
18
19 BEGIN;
20
21 CREATE SCHEMA extend_reporter;
22
23 CREATE TABLE extend_reporter.legacy_circ_count (
24     id          BIGINT   PRIMARY KEY REFERENCES asset.copy (id),
25     circ_count  INT         NOT NULL DEFAULT 0
26 );
27
28 CREATE VIEW extend_reporter.full_circ_count AS
29  SELECT cp.id, COALESCE(sum(c.circ_count), 0::bigint) + COALESCE(count(circ.id), 0::bigint) AS circ_count
30    FROM asset."copy" cp
31    LEFT JOIN extend_reporter.legacy_circ_count c USING (id)
32    LEFT JOIN "action".all_circulation circ ON circ.target_copy = c.id
33   GROUP BY cp.id;
34
35 COMMIT;
36