-
Notifications
You must be signed in to change notification settings - Fork 7
/
database.sql
317 lines (284 loc) · 10.9 KB
/
database.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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
-- Use InnoDB for transaction support?
-- SET storage_engine=InnoDB;
DROP TABLE IF EXISTS logfile_offsets;
DROP TABLE IF EXISTS player_recent_games;
DROP TABLE IF EXISTS all_recent_games;
DROP TABLE IF EXISTS player_best_games;
DROP TABLE IF EXISTS player_last_games;
DROP TABLE IF EXISTS player_first_games;
DROP TABLE IF EXISTS streak_games;
DROP TABLE IF EXISTS streak_breakers;
DROP TABLE IF EXISTS wins;
DROP TABLE IF EXISTS streaks;
DROP TABLE IF EXISTS top_games;
DROP TABLE IF EXISTS top_combo_scores;
DROP TABLE IF EXISTS top_species_scores;
DROP TABLE IF EXISTS top_class_scores;
DROP TABLE IF EXISTS players;
DROP TABLE IF EXISTS player_char_stats;
DROP TABLE IF EXISTS top_killers;
DROP TABLE IF EXISTS killer_recent_kills;
DROP TABLE IF EXISTS ghost_victims;
DROP TABLE IF EXISTS low_xl_rune_finds;
DROP TABLE IF EXISTS ziggurats;
DROP TABLE IF EXISTS per_day_stats;
DROP TABLE IF EXISTS date_players;
DROP TABLE IF EXISTS known_races;
DROP TABLE IF EXISTS known_classes;
DROP TABLE IF EXISTS botnames;
DROP TABLE IF EXISTS version_triage;
-- Keep track of how far we've processed the various logfiles/milestones.
CREATE TABLE logfile_offsets (
id INT AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(100) UNIQUE,
offset BIGINT DEFAULT 0
);
CREATE TABLE botnames (
name VARCHAR(20) UNIQUE NOT NULL
);
-- [greensnark] I've changed the field names for tables containing
-- game entries to be closer to the logfile names. This is
-- inconsistent with the tourney db and with Henzell's primary db,
-- which sucks, but reducing the number of differences between logfile
-- names and field names seems quite important to me.
-- Best games on a per-player basis. Adding a new game must also delete the
-- previous entry by that player.
CREATE TABLE player_best_games (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
-- Source logfile.
source_file VARCHAR(150),
-- game_key in Sequell format. This is reconstructable from other things in
-- the table, as long as you know the logfile->server mappings, but it is
-- convenient to have as its own field.
game_key VARCHAR(50) NOT NULL,
name VARCHAR(20),
start_time DATETIME,
seed VARCHAR(255), -- currently 64bit uint, but allow extra space for changes
sc BIGINT,
race VARCHAR(20),
crace VARCHAR(20),
-- Two letter race abbreviation so we can group by it without pain.
raceabbr CHAR(2) NOT NULL,
clsabbr CHAR(2) NOT NULL,
cls VARCHAR(20),
v VARCHAR(10),
lv VARCHAR(8),
uid INT,
charabbr CHAR(4),
xl INT,
sk VARCHAR(16),
sklev INT,
title VARCHAR(255),
place VARCHAR(16),
br VARCHAR(16),
lvl INT,
ltyp VARCHAR(16),
hp INT,
mhp INT,
mmhp INT,
strength INT,
intelligence INT,
dexterity INT,
god VARCHAR(20),
dur INT,
turn BIGINT,
ktyp VARCHAR(20),
killer VARCHAR(100),
kgroup VARCHAR(100),
ckiller VARCHAR(100),
kaux VARCHAR(255),
-- Kills may be null.
kills INT,
dam INT,
piety INT,
pen INT,
gold INT,
goldfound INT,
goldspent INT,
end_time DATETIME,
tmsg VARCHAR(255),
vmsg VARCHAR(255),
nrune INT DEFAULT 0,
urune INT DEFAULT 0
);
CREATE INDEX player_best_game_pscores ON player_best_games (name, sc);
CREATE TABLE wins AS SELECT * FROM player_best_games;
ALTER TABLE wins ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE wins CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
CREATE UNIQUE INDEX wins_gid ON wins (game_key);
CREATE INDEX wins_name ON wins (name);
CREATE INDEX wins_dur ON wins (dur);
CREATE INDEX wins_turn ON wins (turn);
CREATE INDEX wins_sc ON wins (sc);
CREATE TABLE all_recent_games AS SELECT * FROM player_best_games;
ALTER TABLE all_recent_games ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE all_recent_games CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
CREATE INDEX all_recent_games_end
ON all_recent_games (end_time DESC);
CREATE TABLE player_recent_games AS SELECT * FROM player_best_games;
ALTER TABLE player_recent_games ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE player_recent_games CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
CREATE UNIQUE INDEX player_recent_gid ON player_recent_games (game_key);
CREATE INDEX player_recent_games_name_end
ON player_recent_games (name, end_time DESC);
CREATE INDEX player_recent_games_name_id
ON player_recent_games (name, id);
-- Table for the top games on the servers. How many games we keep here
-- is controlled by the Python code.
-- We want all the same field names, etc. for all games tables, so we create
-- each new table based on the canonical game table (player_best_games).
CREATE TABLE top_games AS SELECT * FROM player_best_games;
ALTER TABLE top_games ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE top_games CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
CREATE INDEX top_games_sc ON top_games (sc);
-- n.b. the unique class/job values will prevent duplicate games in these tables
-- Keep track of best score for each combo (unique charabbr).
CREATE TABLE top_combo_scores AS SELECT * FROM player_best_games;
ALTER TABLE top_combo_scores ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE top_combo_scores CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
ALTER TABLE top_combo_scores Add CONSTRAINT UNIQUE (charabbr);
CREATE INDEX top_combo_scores_name ON top_combo_scores (name, charabbr);
CREATE UNIQUE INDEX top_combo_scores_charabbr
ON top_combo_scores (charabbr);
CREATE INDEX top_combo_scores_sc ON top_combo_scores (sc);
-- Keep track of best score for each species (unique raceabbr).
CREATE TABLE top_species_scores AS SELECT * FROM player_best_games;
ALTER TABLE top_species_scores ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE top_species_scores CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
ALTER TABLE top_species_scores Add CONSTRAINT UNIQUE (raceabbr);
CREATE UNIQUE INDEX top_species_scores_raceabbr
ON top_species_scores (raceabbr);
CREATE INDEX top_species_scores_name ON top_species_scores (name, crace);
-- Keep track of best score for each species (unique cls).
CREATE TABLE top_class_scores AS SELECT * FROM player_best_games;
ALTER TABLE top_class_scores ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE top_class_scores CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
ALTER TABLE top_class_scores Add CONSTRAINT UNIQUE (cls);
CREATE UNIQUE INDEX top_class_scores_cls
ON top_class_scores (cls);
CREATE INDEX top_class_scores_name ON top_class_scores (name, cls);
-- Most recent game by every known player.
CREATE TABLE player_last_games AS SELECT * FROM player_best_games;
ALTER TABLE player_last_games ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE player_last_games CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
ALTER TABLE player_last_games Add CONSTRAINT UNIQUE (name);
CREATE UNIQUE INDEX player_last_games_name
ON player_last_games (name);
-- First known game by every known player
CREATE TABLE player_first_games AS SELECT * FROM player_best_games;
ALTER TABLE player_first_games ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE player_first_games CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
ALTER TABLE player_first_games Add CONSTRAINT UNIQUE (name);
CREATE UNIQUE INDEX player_first_games_name
ON player_first_games (name);
-- Streak games by all players; includes first game in the streak.
CREATE TABLE streak_games AS SELECT * FROM player_best_games;
ALTER TABLE streak_games ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE streak_games CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
ALTER TABLE streak_games ADD CONSTRAINT UNIQUE (game_key);
CREATE INDEX streak_games_name_time ON streak_games (name, end_time);
CREATE TABLE streak_breakers AS SELECT * FROM player_best_games;
ALTER TABLE streak_breakers ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE streak_breakers CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
ALTER TABLE streak_breakers ADD CONSTRAINT UNIQUE (game_key); -- is this needed;
ALTER TABLE streak_breakers ADD COLUMN streak_id BIGINT UNIQUE NOT NULL;
-- Track all streaks by all players.
CREATE TABLE streaks (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
player VARCHAR(20),
start_game_time DATETIME,
end_game_time DATETIME,
active BOOLEAN DEFAULT 0,
ngames INT DEFAULT 0
);
CREATE INDEX streaks_order ON streaks (ngames DESC, id);
CREATE INDEX streaks_player ON streaks (player);
CREATE INDEX streaks_player_active ON streaks (player, active);
-- Player statistics
CREATE TABLE players (
name VARCHAR(20) UNIQUE PRIMARY KEY,
games_played INT DEFAULT 0,
games_won INT DEFAULT 0,
total_score BIGINT,
best_xl TINYINT,
best_score BIGINT,
first_game_start DATETIME,
last_game_end DATETIME,
max_runes TINYINT DEFAULT 0,
-- Combo they're currently playing; used in the active streaks
-- table. This will be set to NULL on end of game, and will only be
-- set to a new value if currently NULL.
current_combo CHAR(4)
);
CREATE INDEX player_total_scores ON players (name, total_score);
CREATE INDEX players_win_stats ON players (games_won DESC, games_played);
-- Statistics on the games the player has played.
CREATE TABLE player_char_stats (
name VARCHAR(20),
charabbr CHAR(4),
games_played INT DEFAULT 0,
best_xl INT DEFAULT 0,
wins INT DEFAULT 0
);
CREATE UNIQUE INDEX player_cstats_name_char
ON player_char_stats (name, charabbr);
CREATE INDEX player_char_stats_name_cab ON player_char_stats (name, charabbr);
CREATE TABLE top_killers (
ckiller VARCHAR(100) UNIQUE PRIMARY KEY,
kills BIGINT DEFAULT 0,
most_recent_victim VARCHAR(20)
);
CREATE INDEX top_killers_kills ON top_killers (kills DESC, ckiller);
CREATE TABLE killer_recent_kills AS SELECT * FROM player_best_games;
ALTER TABLE killer_recent_kills ADD CONSTRAINT PRIMARY KEY (id);
ALTER TABLE killer_recent_kills CHANGE COLUMN id id BIGINT AUTO_INCREMENT;
ALTER TABLE killer_recent_kills Add CONSTRAINT UNIQUE (ckiller);
CREATE INDEX killer_recent_kills_ckiller ON killer_recent_kills (ckiller);
CREATE TABLE ghost_victims (
ghost VARCHAR(100),
victim VARCHAR(20)
);
CREATE INDEX ghost_victims_ghost ON ghost_victims (ghost);
CREATE INDEX ghost_victims_victim ON ghost_victims (victim);
CREATE TABLE low_xl_rune_finds (
player VARCHAR(20),
start_time DATETIME,
rune_time DATETIME,
rune VARCHAR(50),
xl TINYINT
);
CREATE INDEX rune_finds_xl ON low_xl_rune_finds (xl, rune_time);
-- Ziggurat visits; newer visits will overwrite older ones, unlike
-- most other tables.
CREATE TABLE ziggurats (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
player VARCHAR(20),
deepest INT,
place VARCHAR(20),
zig_time DATETIME,
start_time DATETIME
);
CREATE INDEX ziggurats_time ON ziggurats (zig_time);
CREATE TABLE per_day_stats (
which_day DATETIME UNIQUE PRIMARY KEY,
games_ended INT DEFAULT 0,
games_won INT DEFAULT 0
);
CREATE TABLE date_players (
which_day DATETIME,
which_month CHAR(6),
player VARCHAR(20),
games INT DEFAULT 0,
wins INT DEFAULT 0,
PRIMARY KEY (which_day, player)
);
CREATE INDEX date_players_month ON date_players (which_month);
CREATE TABLE known_races (
race CHAR(2) UNIQUE PRIMARY KEY
);
CREATE TABLE known_classes (
cls CHAR(2) UNIQUE PRIMARY KEY
);
CREATE TABLE version_triage(v VARCHAR(10) UNIQUE NOT NULL, major INT, stable BOOLEAN DEFAULT 0, vclean VARCHAR(10), recent BOOLEAN DEFAULT 0);
CREATE INDEX prg_v ON player_recent_games (v);
CREATE INDEX wins_v ON wins (v);