-
Notifications
You must be signed in to change notification settings - Fork 5
/
SQLSETUP
executable file
·295 lines (207 loc) · 7.45 KB
/
SQLSETUP
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
--This project is only tested with PostgreSQL, its working in my sql hasn't been tested. These are the sql commands
-- for the tables and the sequences(used to increment the ids of photos, messages, etc)
-- This file needs correction, check if all relations which contains sequences works...(w_photos, w_groups, w_msgs, w_gmsgid)
--Tables --
CREATE TABLE w_gmsgs (
gmsgid integer NOT NULL,
content character varying(1000),
s_username character varying(30),
r_groupid integer,
send_date_time timestamp without time zone
);
CREATE TABLE w_connections (
username1 character varying(30) NOT NULL,
username2 character varying(30) NOT NULL,
status character(1)
);
CREATE TABLE w_gmsgs (
gmsgid integer NOT NULL,
content character varying(1000),
s_username character varying(30),
r_groupid integer,
send_date_time timestamp without time zone
);
CREATE TABLE w_groups (
groupid integer NOT NULL,
name character varying(20),
description character varying(1000),
type character(1),
owner character varying(30),
create_date_time timestamp without time zone
);
CREATE TABLE w_membership (
username character varying(30) NOT NULL,
groupid integer NOT NULL,
status character(1)
);
CREATE TABLE w_msgs (
msgid integer NOT NULL,
content character varying(1000),
sender character varying(30),
recipent character varying(30),
send_date_time timestamp without time zone,
privacy character(1)
);
CREATE TABLE w_photos (
photoid integer DEFAULT nextval('"w_photos_photoID_seq"'::regclass) NOT NULL,
path character varying(150),
title character varying(50),
description character varying(500),
up_date_time timestamp without time zone,
username character varying(30)
);
CREATE TABLE w_profiles (
username character varying(30) NOT NULL,
fname character varying(20),
lname character varying(20),
dob date,
sex character varying(10),
bio character varying(1000),
profpic character varying(150)
);
CREATE TABLE w_users (
username character varying(30) NOT NULL,
password character varying(32) NOT NULL,
email character varying(30)
);
CREATE SEQUENCE w_gmsgs_gmsgid_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 92233720368547787
START 13370
CACHE 1;
CREATE SEQUENCE w_gmsgs_gmsgid_seq1
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER SEQUENCE w_gmsgs_gmsgid_seq1 OWNED BY w_gmsgs.gmsgid;
CREATE SEQUENCE w_groups_groupid_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 92233720368547787
START 13370
CACHE 1;
CREATE SEQUENCE w_groups_groupid_seq1
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER SEQUENCE w_groups_groupid_seq1 OWNED BY w_groups.groupid;
CREATE SEQUENCE w_msgs_msgid_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 13370
CACHE 1;
CREATE SEQUENCE w_msgs_msgid_seq1
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER SEQUENCE w_msgs_msgid_seq1 OWNED BY w_msgs.msgid;
CREATE SEQUENCE "w_photos_photoD_seq"
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 13370
CACHE 1;
ALTER TABLE ONLY w_connections
ADD CONSTRAINT connections_pkey PRIMARY KEY (username1, username2);
--
-- Name: membership_pkey; Type: CONSTRAINT; Schema: public; Owner: ; Tablespace:
--
ALTER TABLE ONLY w_membership
ADD CONSTRAINT membership_pkey PRIMARY KEY (username, groupid);
--
-- Name: msgs_pkey; Type: CONSTRAINT; Schema: public; Owner: ; Tablespace:
--
ALTER TABLE ONLY w_msgs
ADD CONSTRAINT msgs_pkey PRIMARY KEY (msgid);
--
-- Name: profiles_pkey; Type: CONSTRAINT; Schema: public; Owner: ; Tablespace:
--
ALTER TABLE ONLY w_profiles
ADD CONSTRAINT profiles_pkey PRIMARY KEY (username);
--
-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: ; Tablespace:
--
ALTER TABLE ONLY w_users
ADD CONSTRAINT users_pkey PRIMARY KEY (username);
--
-- Name: w_gmsgs_pkey; Type: CONSTRAINT; Schema: public; Owner: ; Tablespace:
--
ALTER TABLE ONLY w_gmsgs
ADD CONSTRAINT w_gmsgs_pkey PRIMARY KEY (gmsgid);
--
-- Name: w_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: ; Tablespace:
--
ALTER TABLE ONLY w_groups
ADD CONSTRAINT w_groups_pkey PRIMARY KEY (groupid);
--
-- Name: w_photos_pkey; Type: CONSTRAINT; Schema: public; Owner: ; Tablespace:
--
ALTER TABLE ONLY w_photos
ADD CONSTRAINT w_photos_pkey PRIMARY KEY (photoid);
--
-- Name: w_connections_username1_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_connections
ADD CONSTRAINT w_connections_username1_fkey FOREIGN KEY (username1) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_connections_username2_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_connections
ADD CONSTRAINT w_connections_username2_fkey FOREIGN KEY (username2) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_gmsgs_r_groupid_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_gmsgs
ADD CONSTRAINT w_gmsgs_r_groupid_fkey FOREIGN KEY (r_groupid) REFERENCES w_groups(groupid) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_gmsgs_s_username_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_gmsgs
ADD CONSTRAINT w_gmsgs_s_username_fkey FOREIGN KEY (s_username) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_groups_owner_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_groups
ADD CONSTRAINT w_groups_owner_fkey FOREIGN KEY (owner) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_membership_groupid_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_membership
ADD CONSTRAINT w_membership_groupid_fkey FOREIGN KEY (groupid) REFERENCES w_groups(groupid) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_membership_username_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_membership
ADD CONSTRAINT w_membership_username_fkey FOREIGN KEY (username) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_msgs_recipent_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_msgs
ADD CONSTRAINT w_msgs_recipent_fkey FOREIGN KEY (recipent) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_msgs_sender_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_msgs
ADD CONSTRAINT w_msgs_sender_fkey FOREIGN KEY (sender) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_photos_username_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_photos
ADD CONSTRAINT w_photos_username_fkey FOREIGN KEY (username) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: w_profiles_username_fkey; Type: FK CONSTRAINT; Schema: public; Owner:
--
ALTER TABLE ONLY w_profiles
ADD CONSTRAINT w_profiles_username_fkey FOREIGN KEY (username) REFERENCES w_users(username) ON UPDATE CASCADE ON DELETE CASCADE;
/* Change the owner of all the tables to your database username
/* an example
ALTER TABLE public.w_profiles OWNER TO dbownername;
*/