-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from wasade/slight_reorder_and_add_two_years
Reorder height and weight questions and add 2019 / 2020
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-- users requested that height and weight units come before entering the values | ||
|
||
DO | ||
$do$ | ||
DECLARE | ||
q108 integer; | ||
q109 integer; | ||
q113 integer; | ||
q114 integer; | ||
BEGIN | ||
-- store the current display indices | ||
SELECT display_index INTO q108 FROM ag.group_questions WHERE survey_question_id=108; | ||
SELECT display_index INTO q109 FROM ag.group_questions WHERE survey_question_id=109; | ||
SELECT display_index INTO q113 FROM ag.group_questions WHERE survey_question_id=113; | ||
SELECT display_index INTO q114 FROM ag.group_questions WHERE survey_question_id=114; | ||
|
||
-- set 108 to a temp value, put index from 109 as 108, put index from 108 as 109 | ||
UPDATE ag.group_questions SET display_index=123456 WHERE survey_question_id=108; | ||
UPDATE ag.group_questions SET display_index=q108 WHERE survey_question_id=109; | ||
UPDATE ag.group_questions SET display_index=q109 WHERE survey_question_id=108; | ||
|
||
-- set 113 to a temp value, put index from 114 as 113, put index from 113 as 114 | ||
UPDATE ag.group_questions SET display_index=123456 WHERE survey_question_id=113; | ||
UPDATE ag.group_questions SET display_index=q113 WHERE survey_question_id=114; | ||
UPDATE ag.group_questions SET display_index=q114 WHERE survey_question_id=113; | ||
END $do$; | ||
|
||
-- and add missing birth years... (derived from 0040.sql). This is painful. | ||
ALTER TABLE ag.survey_question_response DROP CONSTRAINT idx_survey_question_response; | ||
UPDATE ag.survey_question_response | ||
SET display_index = display_index + 2 | ||
WHERE survey_question_id = 112 AND response != 'Unspecified'; | ||
ALTER TABLE ag.survey_question_response ADD CONSTRAINT idx_survey_question_response UNIQUE ( survey_question_id, display_index ); | ||
|
||
INSERT INTO ag.survey_response (american, british) VALUES ('2019', '2019'); | ||
INSERT INTO ag.survey_response (american, british) VALUES ('2020', '2020'); | ||
INSERT INTO ag.survey_question_response (survey_question_id, response, display_index, spanish, french, chinese) | ||
VALUES (112, '2020', 1, '2020', '2020', '2020'); | ||
INSERT INTO ag.survey_question_response (survey_question_id, response, display_index, spanish, french, chinese) | ||
VALUES (112, '2019', 2, '2019', '2019', '2019'); |