]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0729.vr_format_value_maps.sql
Break up expensive queries, match index to quals
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0729.vr_format_value_maps.sql
1 -- Evergreen DB patch 0729.vr_format_value_maps.sql
2 --
3 BEGIN;
4
5 -- check whether patch can be applied
6 SELECT evergreen.upgrade_deps_block_check('0729', :eg_version);
7
8 CREATE OR REPLACE FUNCTION config.update_coded_value_map(in_ctype TEXT, in_code TEXT, in_value TEXT, in_description TEXT DEFAULT NULL, in_opac_visible BOOL DEFAULT NULL, in_search_label TEXT DEFAULT NULL, in_is_simple BOOL DEFAULT NULL, add_only BOOL DEFAULT FALSE) RETURNS VOID AS $f$
9 DECLARE
10     current_row config.coded_value_map%ROWTYPE;
11 BEGIN
12     -- Look for a current value
13     SELECT INTO current_row * FROM config.coded_value_map WHERE ctype = in_ctype AND code = in_code;
14     -- If we have one..
15     IF FOUND AND NOT add_only THEN
16         -- Update anything we were handed
17         current_row.value := COALESCE(current_row.value, in_value);
18         current_row.description := COALESCE(current_row.description, in_description);
19         current_row.opac_visible := COALESCE(current_row.opac_visible, in_opac_visible);
20         current_row.search_label := COALESCE(current_row.search_label, in_search_label);
21         current_row.is_simple := COALESCE(current_row.is_simple, in_is_simple);
22         UPDATE config.coded_value_map
23             SET
24                 value = current_row.value,
25                 description = current_row.description,
26                 opac_visible = current_row.opac_visible,
27                 search_label = current_row.search_label,
28                 is_simple = current_row.is_simple
29             WHERE id = current_row.id;
30     ELSE
31         INSERT INTO config.coded_value_map(ctype, code, value, description, opac_visible, search_label, is_simple) VALUES
32             (in_ctype, in_code, in_value, in_description, COALESCE(in_opac_visible, TRUE), in_search_label, COALESCE(in_is_simple, FALSE));
33     END IF;
34 END;
35 $f$ LANGUAGE PLPGSQL;
36
37 SELECT config.update_coded_value_map('vr_format', 'a', 'Beta', add_only := TRUE);
38 SELECT config.update_coded_value_map('vr_format', 'b', 'VHS', add_only := TRUE);
39 SELECT config.update_coded_value_map('vr_format', 'c', 'U-matic', add_only := TRUE);
40 SELECT config.update_coded_value_map('vr_format', 'd', 'EIAJ', add_only := TRUE);
41 SELECT config.update_coded_value_map('vr_format', 'e', 'Type C', add_only := TRUE);
42 SELECT config.update_coded_value_map('vr_format', 'f', 'Quadruplex', add_only := TRUE);
43 SELECT config.update_coded_value_map('vr_format', 'g', 'Laserdisc', add_only := TRUE);
44 SELECT config.update_coded_value_map('vr_format', 'h', 'CED videodisc', add_only := TRUE);
45 SELECT config.update_coded_value_map('vr_format', 'i', 'Betacam', add_only := TRUE);
46 SELECT config.update_coded_value_map('vr_format', 'j', 'Betacam SP', add_only := TRUE);
47 SELECT config.update_coded_value_map('vr_format', 'k', 'Super-VHS', add_only := TRUE);
48 SELECT config.update_coded_value_map('vr_format', 'm', 'M-II', add_only := TRUE);
49 SELECT config.update_coded_value_map('vr_format', 'o', 'D-2', add_only := TRUE);
50 SELECT config.update_coded_value_map('vr_format', 'p', '8 mm.', add_only := TRUE);
51 SELECT config.update_coded_value_map('vr_format', 'q', 'Hi-8 mm.', add_only := TRUE);
52 SELECT config.update_coded_value_map('vr_format', 's', 'Blu-ray disc', add_only := TRUE);
53 SELECT config.update_coded_value_map('vr_format', 'u', 'Unknown', add_only := TRUE);
54 SELECT config.update_coded_value_map('vr_format', 'v', 'DVD', add_only := TRUE);
55 SELECT config.update_coded_value_map('vr_format', 'z', 'Other', add_only := TRUE);
56 SELECT config.update_coded_value_map('vr_format', ' ', 'Unspecified', add_only := TRUE);
57
58
59 COMMIT;