-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.sql
99 lines (92 loc) · 2.39 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
CREATE TABLE users(
id integer not null primary key,
reputation int not null,
views int not null,
upvotes int not null,
downvotes int not null,
creation_date text not null,
display_name text not null,
image_url text not null,
last_access_date text not null,
location text not null,
about_me text not null,
email_hash text not null
);
CREATE TABLE badges(
id integer not null primary key,
user_id int not null references users(id),
name text not null,
date text not null
);
CREATE TABLE posts(
id integer not null primary key,
post_type text not null check (post_type in ('question', 'answer', 'wiki', 'tag-wiki-excerpt', 'tag-wiki', 'moderation-nomination', 'wiki-placeholder', 'privilege-wiki')),
score int not null,
views int not null,
answers int not null,
comments int not null,
favorites int not null,
creation_date text not null,
closed_date text,
accepted_answer_id int references posts(id),
parent_id int references posts(id),
owner_user_id int references users(id),
community_owned_date text,
tags text,
title text,
body text not null,
last_editor_user_id int references users(id),
last_edit_date text,
last_activity_date text not null
);
CREATE TABLE votes(
id integer not null primary key,
post_id int not null references posts(id),
-- CONSIDER: translate vote_type_id ?
vote_type text not null check (vote_type in ('accepted', 'up', 'down', 'offensive', 'favorite', 'close', 'reopen', 'bounty-start', 'bounty-close', 'delete', 'undelete', 'spam', 'mod-view-flagged', 'edit-approved')),
creation_date text not null,
user_id int references users(id),
bounty_amount int
);
CREATE TABLE comments(
id integer not null primary key,
post_id int not null references posts(id),
user_id int not null references users(id),
creation_date text not null,
score int not null,
text text not null
);
CREATE VIEW questions AS
SELECT
id,
score,
views,
answers,
comments,
favorites,
creation_date,
closed_date,
accepted_answer_id,
owner_user_id,
community_owned_date,
tags,
title,
body,
last_editor_user_id,
last_edit_date,
last_activity_date
FROM posts WHERE post_type = 'question';
CREATE VIEW answers AS
SELECT
id,
score,
comments,
creation_date,
parent_id,
owner_user_id,
community_owned_date,
body,
last_editor_user_id,
last_edit_date,
last_activity_date
FROM posts WHERE post_type = 'answer';