@@ -6,54 +6,50 @@ CREATE TYPE survey_parse_statuses AS ENUM ('success', 'error', 'deleted');
6
6
7
7
CREATE TYPE survey_delivery_statuses AS ENUM (' launched' , ' stopped' );
8
8
9
- CREATE TABLE
10
- surveys (
11
- id serial NOT NULL PRIMARY KEY ,
12
- uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
13
- created_at timestamp without time zone default (now () at time zone ' utc' ),
14
- parse_status survey_parse_statuses,
15
- delivery_status survey_delivery_statuses,
16
- error_log TEXT ,
17
- name varchar (32 ) NOT NULL UNIQUE,
18
- url_slug varchar (1024 ) NOT NULL UNIQUE,
19
- config JSONB
20
- );
9
+ CREATE TABLE surveys (
10
+ id serial NOT NULL PRIMARY KEY ,
11
+ uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
12
+ created_at timestamp without time zone default (now () at time zone ' utc' ),
13
+ parse_status survey_parse_statuses,
14
+ delivery_status survey_delivery_statuses,
15
+ error_log TEXT ,
16
+ name varchar (32 ) NOT NULL UNIQUE,
17
+ url_slug varchar (1024 ) NOT NULL UNIQUE,
18
+ config JSONB
19
+ );
21
20
22
21
CREATE TYPE surveys_sessions_status AS ENUM (' in_progress' , ' completed' );
23
22
24
- CREATE TABLE
25
- surveys_sessions (
26
- id serial NOT NULL PRIMARY KEY ,
27
- uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
28
- created_at timestamp without time zone default (now () at time zone ' utc' ),
29
- completed_at timestamp without time zone ,
30
- status surveys_sessions_status,
31
- survey_id integer NOT NULL ,
32
- ip_addr varchar (512 ) NULL ,
33
- CONSTRAINT fk_surveys_sessions1 FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
34
- );
35
-
36
- CREATE TABLE
37
- surveys_questions (
38
- id serial NOT NULL PRIMARY KEY ,
39
- uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
40
- survey_id integer NOT NULL ,
41
- question_id varchar (256 ) NOT NULL ,
42
- CONSTRAINT fk_surveys_questions1 FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
43
- );
23
+ CREATE TABLE surveys_sessions (
24
+ id serial NOT NULL PRIMARY KEY ,
25
+ uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
26
+ created_at timestamp without time zone default (now () at time zone ' utc' ),
27
+ completed_at timestamp without time zone ,
28
+ status surveys_sessions_status,
29
+ survey_id integer NOT NULL ,
30
+ ip_addr varchar (512 ) NULL ,
31
+ CONSTRAINT fk_surveys_sessions1 FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
32
+ );
33
+
34
+ CREATE TABLE surveys_questions (
35
+ id serial NOT NULL PRIMARY KEY ,
36
+ uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
37
+ survey_id integer NOT NULL ,
38
+ question_id varchar (256 ) NOT NULL ,
39
+ CONSTRAINT fk_surveys_questions1 FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
40
+ );
44
41
45
42
CREATE UNIQUE INDEX surveys_questions_id ON surveys_questions (survey_id, question_id);
46
43
47
- CREATE TABLE
48
- surveys_answers (
49
- id serial NOT NULL PRIMARY KEY ,
50
- uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
51
- created_at timestamp without time zone default (now () at time zone ' utc' ),
52
- session_id integer NOT NULL ,
53
- question_id integer NOT NULL ,
54
- answer JSONB,
55
- CONSTRAINT fk_surveys_answers1 FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE ,
56
- CONSTRAINT fk_surveys_answers2 FOREIGN KEY (question_id) REFERENCES surveys_questions (id) ON DELETE CASCADE
57
- );
44
+ CREATE TABLE surveys_answers (
45
+ id serial NOT NULL PRIMARY KEY ,
46
+ uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
47
+ created_at timestamp without time zone default (now () at time zone ' utc' ),
48
+ session_id integer NOT NULL ,
49
+ question_id integer NOT NULL ,
50
+ answer JSONB,
51
+ CONSTRAINT fk_surveys_answers1 FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE ,
52
+ CONSTRAINT fk_surveys_answers2 FOREIGN KEY (question_id) REFERENCES surveys_questions (id) ON DELETE CASCADE
53
+ );
58
54
59
55
CREATE UNIQUE INDEX surveys_answers_unique ON surveys_answers (session_id, question_id);
0 commit comments