Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdbinit.sql
More file actions
Latest commit
242 lines (211 loc) · 6.46 KB
/
Copy pathdbinit.sql
File metadata and controls
242 lines (211 loc) · 6.46 KB
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
-- use these 4 lines if database doesn't exist at all, e.g. in Docker
-- on shared hosting you are given ready database and credentials
createdatabaseca;
createuserif not exists 'causer'@'localhost';
grant all privileges on ca.* to 'causer'@'localhost' identified by 'somepwd';
use ca;
-- if all tables should have specific prefix, auto-replace 'pfx_' with it
-- (it may happen on shared hosting)
-- you also may autoremove it (replacing with empty string)
-- if you are sure it is not needed
droptable if exists pfx_users;
createtablepfx_users (
id intprimary key auto_increment,
username varchar(120),
password varchar(120),
loginid varchar(120),
url varchar(120),
index (username),
index (loginid),
index (url)
);
droptable if exists pfx_roles;
createtablepfx_roles (
id intprimary key auto_increment,
userid int,
role varchar(120),
index (userid)
);
droptable if exists pfx_userdata;
createtablepfx_userdata (
id intprimary key auto_increment,
userid int,
solved int default 0,
failed int default 0,
points real default 0,
country varchar(32),
rankpos int default 0,
language varchar(120) default '',
avatar varchar(250) default '',
created timestamp default current_timestamp,
lastlogin timestamp default '0000-00-00',
index (userid)
);
droptable if exists pfx_tasks;
createtablepfx_tasks (
id intprimary key auto_increment,
title varchar(120),
url varchar(120),
volumeid int,
solved int default 0,
cost real default 1,
shown int default 0,
author varchar(120) default null,
lastmod date default '2001-01-01',
index (volumeid),
index (url)
);
droptable if exists pfx_taskdata;
createtablepfx_taskdata (
id intprimary key auto_increment,
taskid int,
type varchar(16),
data text,
index (taskid)
);
droptable if exists pfx_usertasks;
createtablepfx_usertasks (
id intprimary key auto_increment,
userid int,
taskid int,
ts timestamp default current_timestamp,
solved int default 0,
language varchar(120) default '',
variant int default 0,
index (userid),
index (taskid)
);
droptable if exists pfx_tags;
createtablepfx_tags (
id intprimary key auto_increment,
title varchar(32)
);
droptable if exists pfx_tasktags;
createtablepfx_tasktags (
id intprimary key auto_increment,
taskid int,
tagid int,
index (taskid),
index (tagid)
);
droptable if exists pfx_solutions;
createtablepfx_solutions (
id intprimary key auto_increment,
usertaskid int,
viewkey varchar(16),
solution text,
index(usertaskid)
);
droptable if exists pfx_friends;
createtablepfx_friends (
id intprimary key auto_increment,
userid int,
targetid int,
visible int default 1,
index (userid),
index (targetid)
);
droptable if exists pfx_tagval;
createtablepfx_tagval (
id intprimary key auto_increment,
tag varchar(32),
val text,
index (tag)
);
droptable if exists pfx_countries;
createtablepfx_countries (
code varchar(32) primary key,
title varchar(120)
);
droptable if exists pfx_challenges;
createtablepfx_challenges (
id intprimary key auto_increment,
taskid int,
userid int,
score real,
total real,
notes varchar(250),
index (taskid),
index (userid)
);
droptable if exists pfx_forums;
createtablepfx_forums (
id intprimary key auto_increment,
title varchar(250),
info text,
url varchar(250),
minlevel int default 5,
index (url)
);
droptable if exists pfx_forumtopics;
createtablepfx_forumtopics (
id intprimary key auto_increment,
forumid int,
userid int,
taskid int default 0,
title varchar(250),
url varchar(250),
posts int default 0,
created timestamp default current_timestamp,
lastpost timestamp,
lastpostid int,
index (forumid),
index (url)
);
droptable if exists pfx_forumposts;
createtablepfx_forumposts (
id intprimary key auto_increment,
topicid int,
userid int,
created timestamp default current_timestamp,
post text,
index (topicid)
);
droptable if exists pfx_wiki;
createtablepfx_wiki (
id intprimary key auto_increment,
title varchar(120),
url varchar(120),
data text,
lastmod date default '2001-01-01',
index (title),
index (url)
);
droptable if exists pfx_chat;
createtablepfx_chat (
id bigintprimary key auto_increment,
userid int,
created timestamp default current_timestamp,
message text,
index (userid),
index (created)
);
dropview if exists pfx_userrank;
createviewpfx_userrank (id, username, url, solved, failed, points, rankpos, created, country, language, avatar) as
selectu.id, u.username, u.url, d.solved, d.failed, d.points, d.rankpos, d.created, d.country, d.language, d.avatar
from pfx_users u join pfx_userdata d onu.id=d.userid
order byd.rankposdesc;
dropview if exists pfx_tasklist;
createviewpfx_tasklistasselect*from pfx_tasks order by solved desc, id asc;
dropview if exists pfx_userpointstask;
createviewpfx_userpointstaskasselect userid, sum(cost) as sumcost
from pfx_usertasks ut join pfx_tasks t onut.taskid=t.id
whereut.solved>0and variant =0group by userid;
dropview if exists pfx_userpointschlng;
createviewpfx_userpointschlngasselect userid, sum(total) as sumcost
from pfx_challenges where userid <>0group by userid;
dropview if exists pfx_userpoints;
createviewpfx_userpointsasselectpts.userid, pts.sumcost+ coalesce(ch.sumcost, 0) as sumcost
from pfx_userpointstask pts left join pfx_userpointschlng ch using(userid)
order by sumcost desc;
dropview if exists pfx_chatview;
createviewpfx_chatview (id, userid, username, userurl, solved, created, message, avatar) as
selectc.id, c.userid, u.username, u.url, d.solved, c.created, c.message, d.avatar
from pfx_chat c join pfx_users u onc.userid=u.idleft join pfx_userdata d onc.userid=d.userid
wherec.created> (now() - interval 1 day)
order byc.createddesc;
insert into pfx_tags (title) values ('unlabeled');
insert into pfx_countries (code, title) values ('ZZ','Unknown');
insert into pfx_wiki (title, url, data) values ('Help', 'help', 'VGhpcyBpcyBhIG1haW4gaGVscCBwYWdl');
insert into pfx_forums (title, url, minlevel, info) values ('General discussions', 'general', 5,
'V3JpdGUgd2hhdGV2ZXIgaXMgb24geW91ciBtaW5kLCBqdXN0IGJlIHBvbGl0ZSwgcGxlYXNlIDopCg==');