3 SELECT evergreen.upgrade_deps_block_check('0706', :eg_version);
5 -- This throws away data, but only data that causes breakage anyway.
6 UPDATE serial.issuance SET holding_code = NULL WHERE NOT is_json(holding_code);
8 -- If we don't do this, we have unprocessed triggers and we can't alter the table
9 SET CONSTRAINTS serial.issuance_caption_and_pattern_fkey IMMEDIATE;
11 ALTER TABLE serial.issuance ADD CHECK (holding_code IS NULL OR is_json(holding_code));
13 -- For the sake of completeness if these sneaked through
14 ALTER TABLE serial.materialized_holding_code DROP COLUMN IF EXISTS holding_type;
15 ALTER TABLE serial.materialized_holding_code DROP COLUMN IF EXISTS ind1;
16 ALTER TABLE serial.materialized_holding_code DROP COLUMN IF EXISTS ind2;
18 CREATE OR REPLACE FUNCTION serial.materialize_holding_code() RETURNS TRIGGER
25 if (not defined $_TD->{new}{holding_code}) {
26 elog(WARNING, 'NULL in "holding_code" column of serial.issuance allowed for now, but may not be useful');
30 # Do nothing if holding_code has not changed...
32 if ($_TD->{new}{holding_code} eq $_TD->{old}{holding_code}) {
33 # ... unless the following internal flag is set.
35 my $flag_rv = spi_exec_query(q{
36 SELECT * FROM config.internal_flag
37 WHERE name = 'serial.rematerialize_on_same_holding_code' AND enabled
39 return unless $flag_rv->{processed};
43 my $holding_code = (new JSON::XS)->decode($_TD->{new}{holding_code});
45 my $field = new MARC::Field('999', @$holding_code); # tag doesnt matter
47 my $dstmt = spi_prepare(
48 'DELETE FROM serial.materialized_holding_code WHERE issuance = $1',
51 spi_exec_prepared($dstmt, $_TD->{new}{id});
53 my $istmt = spi_prepare(
55 INSERT INTO serial.materialized_holding_code (
56 issuance, subfield, value
61 foreach ($field->subfields) {
72 $func$ LANGUAGE 'plperlu';