liquid_feedback_frontend
view db/survey.sql @ 1748:8d7c4d542c3d
Correctly store answer option for checkboxes
| author | bsw | 
|---|---|
| date | Mon Oct 11 10:55:14 2021 +0200 (2021-10-11) | 
| parents | c7dbb36ce1e0 | 
| children | 2d4136357989 | 
 line source
     1 CREATE TABLE survey (
     2   id SERIAL4 PRIMARY KEY,
     3   title TEXT NOT NULL,
     4   text TEXT NOT NULL,
     5   finished_title TEXT NOT NULL,
     6   finished_text TEXT NOT NULL,
     7   created TIMESTAMPTZ NOT NULL DEFAULT now(),
     8   open_from TIMESTAMPTZ NOT NULL,
     9   open_until TIMESTAMPTZ NOT NULL
    10 );
    12 CREATE TABLE survey_question (
    13   id SERIAL4 PRIMARY KEY,
    14   survey_id INT4 NOT NULL REFERENCES survey(id),
    15   position INT4 NOT NULL,
    16   question TEXT NOT NULL,
    17   description TEXT,
    18   answer_type TEXT NOT NULL,
    19   answer_options json
    20 );
    22 CREATE TABLE survey_answer_set (
    23   ident TEXT NOT NULL PRIMARY KEY,
    24   survey_id INT4 NOT NULL REFERENCES survey(id)
    25 );
    27 CREATE TABLE survey_answer (
    28   id SERIAL8 PRIMARY KEY,
    29   survey_answer_set_ident TEXT NOT NULL REFERENCES survey_answer_set(ident) ON DELETE CASCADE,
    30   survey_question_id INT4 NOT NULL REFERENCES survey_question(id),
    31   answer TEXT NOT NULL
    32 );
    34 CREATE TABLE survey_member (
    35   id SERIAL4 PRIMARY KEY,
    36   survey_id INT4 NOT NULL REFERENCES survey(id),
    37   member_id INT4 NOT NULL REFERENCES member(id),
    38   survey_answer_set_ident TEXT REFERENCES survey_answer_set(ident),
    39   started TIMESTAMPTZ DEFAULT now(),
    40   finished TIMESTAMPTZ,
    41   rejected TIMESTAMPTZ
    42 );
    44 INSERT INTO survey (id, title, text, finished_text, open_from, open_until) VALUES (
    45   1,
    46   'Example survey',
    47   'This is just an example',
    48   '<strong>Done!</strong><br>You finished it. Thank you very much.',
    49   '2021-10-06 12:00',
    50   '2021-10-14 12:00'
    51 );
    53 INSERT INTO survey_question (survey_id, position, question, answer_type, answer_options) VALUES
    54   (1, 1, 'What color do you like?', 'radio', '[ "Red", "Green", "Blue" ]'),
    55   (1, 2, 'What form do you like?', 'radio', '[ "Square", "Circle", "Hexagon" ]')
    56 ;
