3 SELECT evergreen.upgrade_deps_block_check('0700', :eg_version);
5 INSERT INTO config.internal_flag (name, value, enabled) VALUES (
6 'serial.rematerialize_on_same_holding_code', NULL, FALSE
9 INSERT INTO config.org_unit_setting_type (
10 name, label, grp, description, datatype
12 'serial.default_display_grouping',
13 'Default display grouping for serials distributions presented in the OPAC.',
15 'Default display grouping for serials distributions presented in the OPAC. This can be "enum" or "chron".',
19 ALTER TABLE serial.distribution
20 ADD COLUMN display_grouping TEXT NOT NULL DEFAULT 'chron'
21 CHECK (display_grouping IN ('enum', 'chron'));
23 -- why didn't we just make one summary table in the first place?
24 CREATE VIEW serial.any_summary AS
26 'basic' AS summary_type, id, distribution,
27 generated_coverage, textual_holdings, show_generated
28 FROM serial.basic_summary
31 'index' AS summary_type, id, distribution,
32 generated_coverage, textual_holdings, show_generated
33 FROM serial.index_summary
36 'supplement' AS summary_type, id, distribution,
37 generated_coverage, textual_holdings, show_generated
38 FROM serial.supplement_summary ;
41 -- Given the IDs of two rows in actor.org_unit, *the second being an ancestor
42 -- of the first*, return in array form the path from the ancestor to the
43 -- descendant, with each point in the path being an org_unit ID. This is
44 -- useful for sorting org_units by their position in a depth-first (display
45 -- order) representation of the tree.
47 -- This breaks with the precedent set by actor.org_unit_full_path() and others,
48 -- and gets the parameters "backwards," but otherwise this function would
49 -- not be very usable within json_query.
50 CREATE OR REPLACE FUNCTION actor.org_unit_simple_path(INT, INT)
52 WITH RECURSIVE descendant_depth(id, path) AS (
55 FROM actor.org_unit aou
56 JOIN actor.org_unit_type aout ON (aout.id = aou.ou_type)
60 dd.path || ARRAY[aou.id]
61 FROM actor.org_unit aou
62 JOIN actor.org_unit_type aout ON (aout.id = aou.ou_type)
63 JOIN descendant_depth dd ON (dd.id = aou.parent_ou)
65 FROM actor.org_unit aou
66 JOIN descendant_depth dd USING (id)
67 WHERE aou.id = $1 ORDER BY dd.path;
68 $$ LANGUAGE SQL STABLE;
70 CREATE TABLE serial.materialized_holding_code (
71 id BIGSERIAL PRIMARY KEY,
72 issuance INTEGER NOT NULL REFERENCES serial.issuance (id) ON DELETE CASCADE,
77 CREATE OR REPLACE FUNCTION serial.materialize_holding_code() RETURNS TRIGGER
84 # Do nothing if holding_code has not changed...
86 if ($_TD->{new}{holding_code} eq $_TD->{old}{holding_code}) {
87 # ... unless the following internal flag is set.
89 my $flag_rv = spi_exec_query(q{
90 SELECT * FROM config.internal_flag
91 WHERE name = 'serial.rematerialize_on_same_holding_code' AND enabled
93 return unless $flag_rv->{processed};
97 my $holding_code = (new JSON::XS)->decode($_TD->{new}{holding_code});
99 my $field = new MARC::Field('999', @$holding_code); # tag doesnt matter
101 my $dstmt = spi_prepare(
102 'DELETE FROM serial.materialized_holding_code WHERE issuance = $1',
105 spi_exec_prepared($dstmt, $_TD->{new}{id});
107 my $istmt = spi_prepare(
109 INSERT INTO serial.materialized_holding_code (
110 issuance, subfield, value
111 ) VALUES ($1, $2, $3)
115 foreach ($field->subfields) {
126 $func$ LANGUAGE 'plperlu';
128 CREATE INDEX assist_holdings_display
129 ON serial.materialized_holding_code (issuance, subfield);
131 CREATE TRIGGER materialize_holding_code
132 AFTER INSERT OR UPDATE ON serial.issuance
133 FOR EACH ROW EXECUTE PROCEDURE serial.materialize_holding_code() ;
135 -- starting here, we materialize all existing holding codes.
137 UPDATE config.internal_flag
139 WHERE name = 'serial.rematerialize_on_same_holding_code';
141 UPDATE serial.issuance SET holding_code = holding_code;
143 UPDATE config.internal_flag
145 WHERE name = 'serial.rematerialize_on_same_holding_code';
147 -- finish holding code materialization process
149 -- fix up missing holding_code fields from serial.issuance
150 UPDATE serial.issuance siss
151 SET holding_type = scap.type
152 FROM serial.caption_and_pattern scap
153 WHERE scap.id = siss.caption_and_pattern AND siss.holding_type IS NULL;