]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/tests/datasets/sql/assets_extras.sql
LP#1155771 Sample data : copy locations, location groups
[Evergreen.git] / Open-ILS / tests / datasets / sql / assets_extras.sql
1 -- copy locations
2 -- copy location groups
3 -- copy stat cats
4 -- ...
5
6 INSERT INTO asset.copy_location (owning_lib, name) VALUES
7 (4, 'Adult'),
8 (4, 'Young Adult'),
9 (4, 'Juvenile'),
10 (4, 'AV'),
11 (4, 'Children''s AV'),
12 (5, 'Western'),
13 (5, 'Young Adult'),
14 (5, 'Genealogy'),
15 (5, 'Local History'),
16 (6, 'Sci-Fi'),
17 (6, 'Biography'),
18 (6, 'Ninjas'),
19 (6, 'Young Adult'),
20 (7, 'Vampires'),
21 (7, 'Western'),
22 (7, 'Young Adult'),
23 (7, 'Sports');
24
25 -- non-holable
26 INSERT INTO asset.copy_location (owning_lib, name, holdable) VALUES
27 (4, 'New Arrivals', FALSE);
28
29 -- non-holable, non-cirulcateable, non-visible
30 INSERT INTO asset.copy_location
31     (owning_lib, name, holdable, opac_visible, circulate) VALUES
32 (5, 'Display', FALSE, FALSE, FALSE),
33 (6, 'Display', FALSE, FALSE, FALSE),
34 (7, 'Display', FALSE, FALSE, FALSE);
35
36
37 -- copy location groups
38
39 INSERT INTO asset.copy_location_group (name, owner) VALUES ('Sys1 Fiction', 2);
40
41 INSERT INTO asset.copy_location_group_map (lgroup, location)
42     SELECT CURRVAL('asset.copy_location_group_id_seq'), id
43         FROM asset.copy_location WHERE owning_lib in (4, 5)
44         AND opac_visible;
45
46 INSERT INTO asset.copy_location_group (name, owner) VALUES ('Sys2 Fiction', 2);
47
48 INSERT INTO asset.copy_location_group_map (lgroup, location)
49     SELECT CURRVAL('asset.copy_location_group_id_seq'), id
50         FROM asset.copy_location WHERE owning_lib in (6, 7)
51         AND opac_visible;
52
53 -- evenly distribute the copies across all of the copy locations.
54 -- there's probably a more effecient way, but this gets the job done
55
56 DO $$
57     DECLARE cur_loc INTEGER;
58     DECLARE cur_copy asset.copy%ROWTYPE;
59 BEGIN
60     cur_copy := evergreen.next_copy(0);
61
62     WHILE cur_copy.id IS NOT NULL LOOP
63         FOR cur_loc IN SELECT id FROM asset.copy_location ORDER BY id LOOP
64             UPDATE asset.copy SET location = cur_loc WHERE id = cur_copy.id;
65             cur_copy := evergreen.next_copy(cur_copy.id);
66             EXIT WHEN cur_copy.id IS NULL;
67         END LOOP;
68     END LOOP;
69 END $$;