]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/tests/datasets/sql/surveys.sql
LP#1863929 - Fix sample survey data.
[working/Evergreen.git] / Open-ILS / tests / datasets / sql / surveys.sql
1 /** Create a survey */
2 INSERT INTO action.survey (id, owner, name, description) VALUES (1, 1, 'Who would cross the Bridge of Death must answer me these questions three, ere the other side he see.', 'Test survey for concerto dataset');
3
4 /** Populate with questions */
5 INSERT INTO action.survey_question (id, survey, question) VALUES (1, 1, 'What... is your name?');
6 INSERT INTO action.survey_question (id, survey, question) VALUES (2, 1, 'What... is your quest?');
7 INSERT INTO action.survey_question (id, survey, question) VALUES (3, 1, 'What... is your favorite color?');
8
9 /** Attach answers to questions */
10 INSERT INTO action.survey_answer (id, question, answer) VALUES (1, 1, 'My name is Sir Lancelot of Camelot.');
11 INSERT INTO action.survey_answer (id, question, answer) VALUES (2, 1, 'Sir Robin of Camelot.');
12 INSERT INTO action.survey_answer (id, question, answer) VALUES (3, 1, 'Sir Galahad of Camelot.');
13 INSERT INTO action.survey_answer (id, question, answer) VALUES (4, 1, 'General Leia Organa.');
14 INSERT INTO action.survey_answer (id, question, answer) VALUES (5, 1, 'Dr. Beverly Crusher.');
15 INSERT INTO action.survey_answer (id, question, answer) VALUES (6, 1, 'Rose Tyler.');
16 INSERT INTO action.survey_answer (id, question, answer) VALUES (7, 1, 'Sorry, not interested.');
17 INSERT INTO action.survey_answer (id, question, answer) VALUES (8, 2, 'To seek the Holy Grail.');
18 INSERT INTO action.survey_answer (id, question, answer) VALUES (9, 2, 'To go where no one has gone before.');
19 INSERT INTO action.survey_answer (id, question, answer) VALUES (10, 2, 'To steal the plans for the Death Star.');
20 INSERT INTO action.survey_answer (id, question, answer) VALUES (11, 2, 'To save the universe from the Daleks again.');
21 INSERT INTO action.survey_answer (id, question, answer) VALUES (12, 2, 'What is this again?');
22 INSERT INTO action.survey_answer (id, question, answer) VALUES (13, 3, 'Blue');
23 INSERT INTO action.survey_answer (id, question, answer) VALUES (14, 3, 'Blue. No yellow... AAAGGH!');
24 INSERT INTO action.survey_answer (id, question, answer) VALUES (15, 3, 'Jedi cloak brown.');
25 INSERT INTO action.survey_answer (id, question, answer) VALUES (16, 3, 'Redshirt red.');
26 INSERT INTO action.survey_answer (id, question, answer) VALUES (17, 3, 'TARDIS blue.');
27 INSERT INTO action.survey_answer (id, question, answer) VALUES (18, 3, 'This is getting too silly - I quit.');
28
29 SELECT SETVAL('action.survey_id_seq'::TEXT, 100);
30 SELECT SETVAL('action.survey_question_id_seq'::TEXT, 100);
31 SELECT SETVAL('action.survey_answer_id_seq'::TEXT, 100);
32
33 /** for every user with an id not evenly divisible by 6, 
34  *  add a randomized response for every question in the survey
35  */
36 CREATE FUNCTION populate_survey_responses(usr INTEGER) RETURNS VOID AS
37 $BODY$
38 DECLARE q INT;
39 BEGIN
40 IF usr % 6 <> 0 THEN
41     FOR q in 1..3 LOOP
42         INSERT INTO action.survey_response (usr, survey, question, answer, answer_date) VALUES (
43         usr,
44         1,
45         q,
46         (SELECT id FROM action.survey_answer WHERE question = q ORDER BY random() LIMIT 1),
47         now());
48     END LOOP;
49 END IF;
50 END;
51 $BODY$
52 LANGUAGE plpgsql;
53
54 SELECT populate_survey_responses(id) FROM actor.usr;
55
56 DROP FUNCTION populate_survey_responses(usr INTEGER);