]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/tests/datasets/sql/assets_concerto.sql
3c5d01c574ff73e019cc797ed2143ec8639c59ce
[working/Evergreen.git] / Open-ILS / tests / datasets / sql / assets_concerto.sql
1 -- Create call numbers
2 SELECT evergreen.populate_call_number(4, 'CONCERTO ', 'IMPORT CONCERTO'); -- BR1
3 SELECT evergreen.populate_call_number(5, 'CONCERTO ', 'IMPORT CONCERTO'); -- BR2
4 SELECT evergreen.populate_call_number(6, 'CONCERTO ', 'IMPORT CONCERTO'); -- BR3
5 SELECT evergreen.populate_call_number(7, 'CONCERTO ', 'IMPORT CONCERTO'); -- BR4
6 SELECT evergreen.populate_call_number(9, 'CONCERTO ', 'IMPORT CONCERTO'); -- BM1
7 SELECT evergreen.populate_call_number(4, 'PERFORM ',  'IMPORT CONCERTO'); -- BR1
8 SELECT evergreen.populate_call_number(5, 'PERFORM ',  'IMPORT CONCERTO'); -- BR2
9 SELECT evergreen.populate_call_number(6, 'PERFORM ',  'IMPORT CONCERTO'); -- BR3
10 SELECT evergreen.populate_call_number(7, 'PERFORM ',  'IMPORT CONCERTO'); -- BR4
11 SELECT evergreen.populate_call_number(9, 'PERFORM ',  'IMPORT CONCERTO'); -- BM1
12
13 -- Create copies
14 SELECT evergreen.populate_copy(4, 4, 'CONC40000', 'CONCERTO'); -- BR1
15 SELECT evergreen.populate_copy(5, 5, 'CONC50000', 'CONCERTO'); -- BR2
16 SELECT evergreen.populate_copy(6, 6, 'CONC60000', 'CONCERTO'); -- BR3
17 SELECT evergreen.populate_copy(7, 7, 'CONC70000', 'CONCERTO'); -- BR4
18 SELECT evergreen.populate_copy(9, 9, 'CONC90000', 'CONCERTO'); -- BM1
19
20 SELECT evergreen.populate_copy(4, 4, 'CONC41000', 'CONCERTO'); -- BR1
21 SELECT evergreen.populate_copy(5, 5, 'CONC51000', 'CONCERTO'); -- BR2
22 SELECT evergreen.populate_copy(6, 6, 'CONC61000', 'CONCERTO'); -- BR3
23 SELECT evergreen.populate_copy(7, 7, 'CONC71000', 'CONCERTO'); -- BR4
24 SELECT evergreen.populate_copy(9, 9, 'CONC91000', 'CONCERTO'); -- BM1
25
26 SELECT evergreen.populate_copy(4, 4, 'CONC42000', 'CONCERTO'); -- BR1
27 SELECT evergreen.populate_copy(5, 5, 'CONC52000', 'CONCERTO'); -- BR2
28 SELECT evergreen.populate_copy(6, 6, 'CONC62000', 'CONCERTO'); -- BR3
29 SELECT evergreen.populate_copy(7, 7, 'CONC72000', 'CONCERTO'); -- BR4
30 SELECT evergreen.populate_copy(9, 9, 'CONC92000', 'CONCERTO'); -- BM1
31
32 SELECT evergreen.populate_copy(4, 4, 'CONC43000', 'CONCERTO'); -- BR1
33 SELECT evergreen.populate_copy(5, 5, 'CONC53000', 'CONCERTO'); -- BR2
34 SELECT evergreen.populate_copy(6, 6, 'CONC63000', 'CONCERTO'); -- BR3
35 SELECT evergreen.populate_copy(7, 7, 'CONC73000', 'CONCERTO'); -- BR4
36 SELECT evergreen.populate_copy(9, 9, 'CONC93000', 'CONCERTO'); -- BM1
37
38 SELECT evergreen.populate_copy(4, 4, 'CONC44000', 'CONCERTO'); -- BR1
39 SELECT evergreen.populate_copy(5, 5, 'CONC54000', 'CONCERTO'); -- BR2
40 SELECT evergreen.populate_copy(6, 6, 'CONC64000', 'CONCERTO'); -- BR3
41 SELECT evergreen.populate_copy(7, 7, 'CONC74000', 'CONCERTO'); -- BR4
42 SELECT evergreen.populate_copy(9, 9, 'CONC94000', 'CONCERTO'); -- BM1
43
44 SELECT evergreen.populate_copy(4, 4, 'CONC40000', 'PERFORM'); -- BR1
45 SELECT evergreen.populate_copy(5, 5, 'CONC50000', 'PERFORM'); -- BR2
46 SELECT evergreen.populate_copy(6, 6, 'CONC60000', 'PERFORM'); -- BR3
47 SELECT evergreen.populate_copy(7, 7, 'CONC70000', 'PERFORM'); -- BR4
48 SELECT evergreen.populate_copy(9, 9, 'CONC90000', 'PERFORM'); -- BM1
49
50 SELECT evergreen.populate_copy(4, 4, 'CONC41000', 'PERFORM'); -- BR1
51 SELECT evergreen.populate_copy(5, 5, 'CONC51000', 'PERFORM'); -- BR2
52 SELECT evergreen.populate_copy(6, 6, 'CONC61000', 'PERFORM'); -- BR3
53 SELECT evergreen.populate_copy(7, 7, 'CONC71000', 'PERFORM'); -- BR4
54 SELECT evergreen.populate_copy(9, 9, 'CONC91000', 'PERFORM'); -- BM1
55
56 -- Delete some copies, call numbers, and bib records
57 DELETE FROM biblio.record_entry
58     WHERE id IN (10, 20);
59
60 DELETE FROM asset.call_number
61     WHERE record IN (30, 40) AND owning_lib = 4;
62
63 DELETE FROM asset.copy
64     WHERE call_number IN (
65         SELECT id FROM asset.call_number
66             WHERE record IN (50, 60)
67     ) AND circ_lib = 5;
68
69 -- Add some prefixes and suffixes
70 INSERT INTO asset.call_number_prefix (owning_lib, label) VALUES
71     (4, 'REF BR1'), (5, 'DVD BR2'), (7, 'STORAGE BR4');
72
73 INSERT INTO asset.call_number_suffix (owning_lib, label) VALUES
74     (4, 'REFERENCE'), (5, 'MEDIA'), (7, 'DEPOSITORY');
75
76 -- Some call numbers will have both prefixes and suffixes
77 UPDATE asset.call_number
78     SET prefix = 1, suffix = 1
79     WHERE owning_lib = 4 AND record IN (35, 45);
80
81 UPDATE asset.call_number
82     SET prefix = 2, suffix = 2
83     WHERE owning_lib = 5 AND record IN (55, 65);
84
85 -- Some call numbers will have either a prefix or a suffix
86 UPDATE asset.call_number
87     SET prefix = 3
88     WHERE owning_lib = 7 AND record IN (75);
89
90 UPDATE asset.call_number
91     SET suffix = 3
92     WHERE owning_lib = 7 AND record IN (85);
93
94 -- Create some bibliographic parts
95 INSERT INTO biblio.monograph_part (record, label) VALUES
96     -- "Virtuoso wind concertos"
97     (84, 'DISC 1'), (84, 'DISC 2'), (84, 'DISC 3'), (84, 'DISC 4'),
98     -- "6 double concertos"
99     (53, 'DISC 1'), (53, 'DISC 2'), (53, 'DISC 3'), (53, 'DISC 4');
100
101 -- Create additional copies for the parts
102 INSERT INTO asset.copy (call_number, circ_lib, creator, editor, loan_duration, fine_level, barcode)
103     SELECT id, owning_lib, 1, 1, 1, 1, 'CONC70001' || id::text
104     FROM asset.call_number
105     WHERE record IN (53, 84) AND label LIKE 'CONCERTO %' AND owning_lib = 7;
106
107 INSERT INTO asset.copy (call_number, circ_lib, creator, editor, loan_duration, fine_level, barcode)
108     SELECT id, owning_lib, 1, 1, 1, 1, 'CONC70002' || id::text
109     FROM asset.call_number
110     WHERE record IN (53, 84) AND label LIKE 'CONCERTO %' AND owning_lib = 7;
111
112 -- Assign the copies to the parts
113 INSERT INTO asset.copy_part_map (target_copy, part)
114     SELECT DISTINCT ON (ac.id) ac.id, bmp.id
115     FROM asset.copy ac INNER JOIN asset.call_number acn
116             ON ac.call_number = acn.id
117         INNER JOIN biblio.monograph_part bmp
118             ON acn.record = bmp.record
119     WHERE bmp.record IN (53, 84)
120         AND ac.circ_lib = 7;
121
122 -- Create some conjoined items:
123 -- Create a new conjoined item type
124 INSERT INTO biblio.peer_type (name)
125     VALUES ('Media player');
126
127 -- Create additional copies for the conjoined items
128 INSERT INTO asset.copy (call_number, circ_lib, creator, editor, loan_duration, fine_level, barcode)
129     SELECT id, owning_lib, 1, 1, 1, 1, 'PEERBIB' || record::text
130     FROM asset.call_number
131     WHERE record = 15 AND label LIKE 'CONCERTO %' AND owning_lib = 4;
132
133 -- Create the peer bib copy map
134 INSERT INTO biblio.peer_bib_copy_map (peer_type, peer_record, target_copy)
135     SELECT bpt.id, acn.record, ac.id
136     FROM biblio.peer_type bpt
137         INNER JOIN asset.copy ac ON bpt.name = 'Media player'
138         INNER JOIN asset.call_number acn ON ac.barcode LIKE 'PEERBIB%'
139         AND ac.circ_lib = 4
140         AND acn.record IN (24, 93, 97, 100)
141     GROUP BY bpt.id, acn.record, ac.id;