</links>
</class>
+ <class id="circbyyr" controller="open-ils.cstore" oils_obj:fieldmapper="action::circ_counts_by_year" oils_persist:tablename="action.circ_counts_by_year" oils_persist:readonly="true">
+ <oils_persist:source_definition>
+
+ SELECT id, SUM(count) AS count, year, is_renewal FROM (
+ SELECT
+ cp.id,
+ COUNT(circ.id),
+ EXTRACT(YEAR FROM circ.xact_start) AS year,
+ (phone_renewal OR desk_renewal OR opac_renewal) as is_renewal
+ FROM
+ asset.copy cp
+ JOIN action.circulation circ ON (cp.id = circ.target_copy)
+ GROUP BY 1, 3, 4
+ UNION
+ SELECT
+ cp.id,
+ COUNT(circ.id),
+ EXTRACT(YEAR FROM circ.xact_start) AS year,
+ (phone_renewal OR desk_renewal OR opac_renewal) as is_renewal
+ FROM
+ asset.copy cp
+ JOIN action.aged_circulation circ ON (cp.id = circ.target_copy)
+ GROUP BY 1, 3, 4
+ UNION
+ SELECT
+ id,
+ circ_count,
+ -1 AS year,
+ false as is_renewal
+ FROM
+ extend_reporter.legacy_circ_count
+ )x GROUP BY 1, 3, 4
+
+ </oils_persist:source_definition>
+ <fields>
+ <field reporter:label="Copy ID" name="id" reporter:datatype="link"/>
+ <field reporter:label="Count" name="count" reporter:datatype="int"/>
+ <field reporter:label="Year" name="year" reporter:datatype="int"/>
+ <field reporter:label="Renewal" name="is_renewal" reporter:datatype="bool"/>
+ </fields>
+ <links>
+ <link field="id" reltype="has_a" key="id" map="" class="acp"/>
+ </links>
+ </class>
+
<class id="rodcirc" controller="open-ils.reporter-store" oils_obj:fieldmapper="reporter::overdue_circs" oils_persist:tablename="reporter.overdue_circs" reporter:core="true" reporter:label="Overdue Circulation">
<fields oils_persist:primary="id" oils_persist:sequence="money.billable_xact_id_seq">
<field reporter:label="Check In Library" name="checkin_lib" reporter:datatype="org_unit"/>
--- /dev/null
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0017');
+
+CREATE INDEX action_circulation_target_copy_idx
+ON action.circulation (target_copy);
+
+CREATE INDEX action_aged_circulation_target_copy_idx ON
+ON action.aged_circulation (target_copy);
+
+COMMIT;