-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema-base.sql
122 lines (114 loc) · 3.18 KB
/
schema-base.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
-- noinspection SqlNoDataSourceInspectionForFile
-- Do i need this
SET
@@SESSION.SQL_MODE='';
create table badges
(
Id INT NOT NULL PRIMARY KEY,
UserId INT,
Name VARCHAR(50),
Date DATETIME,
Class INT,
BadgeClass INT,
TagBased TINYINT
) CHARACTER SET = utf8;
CREATE TABLE comments
(
Id INT NOT NULL PRIMARY KEY,
PostId INT,
Score INT DEFAULT 0,
Text TEXT,
CreationDate DATETIME,
UserDisplayName VARCHAR(50),
UserId INT,
ContentLicense VARCHAR(20)
) CHARACTER SET = utf8;
CREATE TABLE post_history
(
Id INT NOT NULL PRIMARY KEY,
PostHistoryTypeId SMALLINT,
PostId INT,
RevisionGUID VARCHAR(36),
CreationDate DATETIME,
UserId INT,
UserDisplayName VARCHAR(36),
Comment TEXT,
CloseReasonTypes SMALLINT,
PostNoticeId INT,
Text TEXT,
ContentLicense VARCHAR(20)
) CHARACTER SET = utf8;
CREATE TABLE posts
(
Id INT NOT NULL PRIMARY KEY,
PostTypeId SMALLINT,
AcceptedAnswerId INT,
ParentId INT,
Score INT NULL,
ViewCount INT NULL,
Body mediumtext NULL,
OwnerUserId INT,
OwnerDisplayName VARCHAR(50),
LastEditorUserId INT,
LastEditorDisplayName VARCHAR(50),
LastEditDate DATETIME,
LastActivityDate DATETIME,
CommunityOwnedDate DATETIME,
ClosedDate DATETIME,
Title varchar(256),
Tags VARCHAR(256),
AnswerCount INT DEFAULT 0,
CommentCount INT DEFAULT 0,
FavoriteCount INT DEFAULT 0,
CreationDate DATETIME,
ContentLicense VARCHAR(20)
) CHARACTER SET = utf8;
CREATE TABLE users
(
Id INT NOT NULL PRIMARY KEY,
Reputation INT NOT NULL,
CreationDate DATETIME,
DisplayName VARCHAR(50) NULL,
LastAccessedDate DATETIME,
Views INT DEFAULT 0,
WebsiteUrl VARCHAR(256) NULL,
Location VARCHAR(256) NULL,
AboutMe TEXT NULL,
Age INT,
UpVotes INT,
DownVotes INT,
ProfileImageUrl VARCHAR(256) NULL,
EmailHash VARCHAR(32),
AccountId INT
) CHARACTER SET = utf8;
CREATE TABLE votes
(
Id INT NOT NULL PRIMARY KEY,
PostId INT,
VoteTypeId SMALLINT,
UserId INT,
CreationDate DATETIME,
BountyAmount INT
) CHARACTER SET = utf8;
-- Use indices for ease of loading...
-- TODO: Best indices to make
create
index badges_idx_1 on badges(UserId);
create
index comments_idx_1 on comments(PostId);
create
index comments_idx_2 on comments(UserId);
create
index post_history_idx_1 on post_history(PostId);
create
index post_history_idx_2 on post_history(UserId);
create
index posts_idx_1 on posts(AcceptedAnswerId);
create
index posts_idx_2 on posts(ParentId);
create
index posts_idx_3 on posts(OwnerUserId);
create
index posts_idx_4 on posts(LastEditorUserId);
create
index votes_idx_1 on votes(PostId);