-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.sql
203 lines (176 loc) · 5.54 KB
/
db.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
CREATE TABLE sub_tier (
sub_tier_id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(64)
);
CREATE TABLE project_type (
project_type_id SERIAL PRIMARY KEY NOT NULL,
type VARCHAR(64)
);
CREATE TABLE users (
user_id SERIAL PRIMARY KEY NOT NULL,
email VARCHAR(64) NOT NULL,
password VARCHAR(64) NOT NULL,
name VARCHAR(32) NOT NULL,
surname VARCHAR(32) NOT NULL,
linkedin VARCHAR(100),
github VARCHAR(100),
bio VARCHAR(300),
portfolio VARCHAR(100),
credit_count SMALLINT NOT NULL,
match_credit SMALLINT NOT NULL,
create_time TIMESTAMP NOT NULL,
sub_tier_id SERIAL NOT NULL REFERENCES sub_tier(sub_tier_id),
UNIQUE(email)
);
CREATE TABLE project (
project_id SERIAL PRIMARY KEY NOT NULL,
creator_id SERIAL REFERENCES users(user_id),
name VARCHAR(100) NOT NULL,
description VARCHAR(3000) NOT NULL,
summary VARCHAR(500),
repo VARCHAR(100),
credit_count SMALLINT NOT NULL,
create_time TIMESTAMP NOT NULL,
member_count INTEGER,
project_type_id SERIAL REFERENCES project_type(project_type_id)
);
CREATE TABLE field (
field_id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(64)
);
CREATE TABLE skill (
skill_id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(64)
);
CREATE TABLE user_field (
user_id SERIAL NOT NULL REFERENCES users(user_id),
field_id SERIAL NOT NULL REFERENCES field(field_id),
PRIMARY KEY(user_id, field_id)
);
CREATE TABLE user_skill (
user_id SERIAL NOT NULL REFERENCES users(user_id),
skill_id SERIAL NOT NULL REFERENCES skill(skill_id),
PRIMARY KEY(user_id, skill_id)
);
CREATE TABLE tag (
tag_id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(64)
);
CREATE TABLE project_tag (
project_id SERIAL NOT NULL REFERENCES project(project_id),
tag_id SERIAL NOT NULL REFERENCES tag(tag_id),
PRIMARY KEY(project_id, tag_id)
);
CREATE TABLE resource (
resource_id SERIAL PRIMARY KEY NOT NULL,
project_id SERIAL NOT NULL REFERENCES project(project_id),
title VARCHAR(100),
link VARCHAR(100) NOT NULL
);
CREATE TABLE application (
project_id SERIAL NOT NULL REFERENCES project(project_id),
user_id SERIAL NOT NULL REFERENCES users(user_id),
credit_count SMALLINT,
application_time TIMESTAMP NOT NULL,
PRIMARY KEY(project_id, user_id)
);
CREATE TABLE member (
project_id SERIAL NOT NULL REFERENCES project(project_id),
user_id SERIAL NOT NULL REFERENCES users(user_id),
member_time TIMESTAMP NOT NULL,
PRIMARY KEY(project_id, user_id)
);
CREATE TABLE invite (
project_id SERIAL NOT NULL REFERENCES project(project_id),
user_id SERIAL NOT NULL REFERENCES users(user_id),
invite_time TIMESTAMP NOT NULL,
PRIMARY KEY(project_id, user_id)
);
CREATE TABLE request (
project_id SERIAL NOT NULL REFERENCES project(project_id),
user_id SERIAL NOT NULL REFERENCES users(user_id),
request_time TIMESTAMP NOT NULL,
PRIMARY KEY(project_id, user_id)
);
CREATE TABLE task (
task_id SERIAL PRIMARY KEY NOT NULL,
creator_id SERIAL REFERENCES users(user_id),
title VARCHAR(160) NOT NULL,
description VARCHAR(2000) NOT NULL,
repo VARCHAR(100),
credit_count SMALLINT,
credit_reward SMALLINT,
answer_count INTEGER,
commit_count INTEGER,
create_time TIMESTAMP NOT NULL
);
CREATE TABLE commit (
task_id SERIAL NOT NULL REFERENCES task(task_id),
user_id SERIAL NOT NULL REFERENCES users(user_id),
commit_time TIMESTAMP NOT NULL
PRIMARY KEY(task_id, user_id)
);
CREATE TABLE answer (
answer_id SERIAL PRIMARY KEY NOT NULL,
task_id SERIAL NOT NULL REFERENCES task(task_id),
responder_id SERIAL NOT NULL REFERENCES users(user_id),
repo VARCHAR(100),
answer VARCHAR(10000) NOT NULL,
points SMALLINT NOT NULL,
create_time TIMESTAMP NOT NULL
);
CREATE TABLE comment (
comment_id SERIAL PRIMARY KEY NOT NULL,
answer_id SERIAL NOT NULL REFERENCES answer(answer_id),
user_id SERIAL NOT NULL REFERENCES users(user_id),
comment VARCHAR(2000) NOT NULL,
create_time TIMESTAMP NOT NULL
);
CREATE TABLE project_field (
project_id SERIAL NOT NULL REFERENCES project(project_id),
field_id SERIAL NOT NULL REFERENCES field(field_id),
PRIMARY KEY(project_id, field_id)
);
CREATE TABLE project_skill (
project_id SERIAL NOT NULL REFERENCES project(project_id),
skill_id SERIAL NOT NULL REFERENCES skill(skill_id),
PRIMARY KEY(project_id, skill_id)
);
CREATE TABLE task_field (
task_id SERIAL NOT NULL REFERENCES task(task_id),
field_id SERIAL NOT NULL REFERENCES field(field_id),
PRIMARY KEY(task_id, field_id)
);
CREATE TABLE task_skill (
task_id SERIAL NOT NULL REFERENCES task(task_id),
skill_id SERIAL NOT NULL REFERENCES skill(skill_id),
PRIMARY KEY(task_id, skill_id)
);
CREATE TABLE task_tag (
task_id SERIAL NOT NULL REFERENCES task(task_id),
tag_id SERIAL NOT NULL REFERENCES tag(tag_id),
PRIMARY KEY(task_id, tag_id)
);
CREATE TABLE match_project (
project_id SERIAL NOT NULL REFERENCES project(project_id),
user_id SERIAL NOT NULL REFERENCES users(user_id),
match_time TIMESTAMP NOT NULL,
PRIMARY KEY(project_id, user_id)
);
CREATE TABLE match_task (
task_id SERIAL NOT NULL REFERENCES task(task_id),
user_id SERIAL NOT NULL REFERENCES users(user_id),
match_time TIMESTAMP NOT NULL,
PRIMARY KEY(task_id, user_id)
);
CREATE TABLE notification (
notification_id SERIAL PRIMARY KEY NOT NULL,
owner_id SERIAL NOT NULL REFERENCES users(user_id),
causer_id SERIAL NOT NULL REFERENCES users(user_id),
type VARCHAR(32) NOT NULL,
action VARCHAR(32) NOT NULL,
object_id SERIAL NOT NULL,
object_name VARCHAR(64) NOT NULL,
is_seen BOOLEAN NOT NULL,
create_time TIMESTAMP NOT NULL
);