-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
267 lines (179 loc) · 6.21 KB
/
schema.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.3 (Ubuntu 12.3-1.pgdg20.04+1)
-- Dumped by pg_dump version 12.3 (Ubuntu 12.3-1.pgdg20.04+1)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
--
-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: ballots; Type: TABLE; Schema: public; Owner: jwlarocque
--
CREATE TABLE public.ballots (
ballot_id integer NOT NULL,
question_id uuid NOT NULL,
user_id character varying(80) NOT NULL
);
ALTER TABLE public.ballots OWNER TO jwlarocque;
--
-- Name: ballots_ballot_id_seq; Type: SEQUENCE; Schema: public; Owner: jwlarocque
--
ALTER TABLE public.ballots ALTER COLUMN ballot_id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.ballots_ballot_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: options; Type: TABLE; Schema: public; Owner: jwlarocque
--
CREATE TABLE public.options (
option_id integer NOT NULL,
question_id uuid NOT NULL,
text character varying(128)
);
ALTER TABLE public.options OWNER TO jwlarocque;
--
-- Name: questions; Type: TABLE; Schema: public; Owner: jwlarocque
--
CREATE TABLE public.questions (
name character varying(128),
user_id character varying(80) NOT NULL,
type integer NOT NULL,
question_id uuid DEFAULT public.uuid_generate_v1() NOT NULL
);
ALTER TABLE public.questions OWNER TO jwlarocque;
--
-- Name: results; Type: TABLE; Schema: public; Owner: jwlarocque
--
CREATE TABLE public.results (
question_id uuid NOT NULL,
round_num integer NOT NULL,
option_id integer NOT NULL,
num_votes integer NOT NULL
);
ALTER TABLE public.results OWNER TO jwlarocque;
--
-- Name: sessions; Type: TABLE; Schema: public; Owner: jwlarocque
--
CREATE TABLE public.sessions (
session_id character varying(80) NOT NULL,
user_id character varying(80) NOT NULL,
created timestamp without time zone NOT NULL,
expires timestamp without time zone NOT NULL
);
ALTER TABLE public.sessions OWNER TO jwlarocque;
--
-- Name: users; Type: TABLE; Schema: public; Owner: jwlarocque
--
CREATE TABLE public.users (
user_id character varying(80) NOT NULL,
email character varying(256)
);
ALTER TABLE public.users OWNER TO jwlarocque;
--
-- Name: votes; Type: TABLE; Schema: public; Owner: jwlarocque
--
CREATE TABLE public.votes (
ballot_id integer NOT NULL,
option_id integer NOT NULL,
state integer NOT NULL
);
ALTER TABLE public.votes OWNER TO jwlarocque;
--
-- Name: ballots ballots_ballot_id_key; Type: CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.ballots
ADD CONSTRAINT ballots_ballot_id_key UNIQUE (ballot_id);
--
-- Name: ballots ballots_pkey; Type: CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.ballots
ADD CONSTRAINT ballots_pkey PRIMARY KEY (question_id, user_id);
--
-- Name: options options_pkey; Type: CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.options
ADD CONSTRAINT options_pkey PRIMARY KEY (option_id, question_id);
--
-- Name: questions questions_pk; Type: CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.questions
ADD CONSTRAINT questions_pk PRIMARY KEY (question_id);
--
-- Name: results results_pkey; Type: CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.results
ADD CONSTRAINT results_pkey PRIMARY KEY (question_id, round_num, option_id);
--
-- Name: sessions session_pkey; Type: CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.sessions
ADD CONSTRAINT session_pkey PRIMARY KEY (user_id);
--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);
--
-- Name: votes votes_pkey; Type: CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.votes
ADD CONSTRAINT votes_pkey PRIMARY KEY (ballot_id, option_id);
--
-- Name: ballots ballots_question_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.ballots
ADD CONSTRAINT ballots_question_id_fkey FOREIGN KEY (question_id) REFERENCES public.questions(question_id);
--
-- Name: ballots ballots_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.ballots
ADD CONSTRAINT ballots_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(user_id);
--
-- Name: options options_question_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.options
ADD CONSTRAINT options_question_id_fkey FOREIGN KEY (question_id) REFERENCES public.questions(question_id);
--
-- Name: questions questions_user_id; Type: FK CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.questions
ADD CONSTRAINT questions_user_id FOREIGN KEY (user_id) REFERENCES public.users(user_id);
--
-- Name: results results_question_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.results
ADD CONSTRAINT results_question_id_fkey FOREIGN KEY (question_id) REFERENCES public.questions(question_id);
--
-- Name: sessions sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.sessions
ADD CONSTRAINT sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(user_id);
--
-- Name: votes votes_ballot_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: jwlarocque
--
ALTER TABLE ONLY public.votes
ADD CONSTRAINT votes_ballot_id_fkey FOREIGN KEY (ballot_id) REFERENCES public.ballots(ballot_id) ON DELETE CASCADE;
--
-- PostgreSQL database dump complete
--