-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdev_006_create_question_assessment.sql
39 lines (35 loc) · 1.23 KB
/
dev_006_create_question_assessment.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE table question
(
id uuid DEFAULT uuid_generate_v4 (),
form_id VARCHAR(100) NOT NULL,
form_version VARCHAR(10),
x_path VARCHAR(500) NOT NULL,
question_type VARCHAR(500) NOT NULL,
meta JSONB,
created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (id)
);
CREATE INDEX idx_form ON question(form_id, form_version);
CREATE INDEX idx_xPath ON question(x_path);
CREATE INDEX idx_ques_type ON question(question_type);
CREATE table assessment
(
id uuid DEFAULT uuid_generate_v4 (),
question uuid,
answer text,
bot_id uuid,
user_id uuid,
device_id uuid,
meta JSONB,
created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (id),
CONSTRAINT fk_question
FOREIGN KEY (question)
REFERENCES question(id)
);
CREATE INDEX idx_assessment_bot_id ON assessment(bot_id);
CREATE INDEX idx_assessment_user_id ON assessment(user_id);
CREATE INDEX idx_assessment_device_id ON assessment(device_id);