-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.sql
1903 lines (1643 loc) · 51.1 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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- TODO: Upgrade/install?
CREATE TABLE versions (
id_version int(10) unsigned NOT NULL auto_increment,
value int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Numeric value of the version, may have duplicates.',
title varchar(32) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (id_version),
KEY value (id_version, value),
UNIQUE KEY title (title)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE games (
id_game char(14) CHARACTER SET latin1 NOT NULL COMMENT 'Without hyphen.',
title varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (id_game)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE report_message_kinds (
id_msg_kind int(10) unsigned NOT NULL auto_increment,
message varchar(1024) NOT NULL DEFAULT '',
hash binary(20) NOT NULL,
PRIMARY KEY (id_msg_kind),
KEY hash (hash)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE report_messages (
id_msg int(10) unsigned NOT NULL auto_increment,
id_msg_kind int(10) unsigned NOT NULL,
id_game char(14) CHARACTER SET latin1 NOT NULL COMMENT 'Without hyphen.',
formatted_message varchar(4096) NOT NULL DEFAULT '',
formatted_hash binary(20) NOT NULL,
PRIMARY KEY (id_msg),
UNIQUE KEY `id_msg_kind-id_game-formatted_hash` (id_msg_kind, id_game, formatted_hash)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE report_message_versions (
id_msg int(10) unsigned NOT NULL,
id_version int(10) unsigned NOT NULL,
first_report datetime NOT NULL,
latest_report datetime NOT NULL,
hits smallint(5) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (id_msg, id_version),
KEY `id_version-latest_report` (id_version, latest_report)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE report_messages
CHANGE COLUMN formatted_message formatted_message varchar(4096) NOT NULL DEFAULT '';
CREATE TABLE gpus (
id_gpu mediumint(8) unsigned NOT NULL auto_increment,
short_desc varchar(96) NOT NULL DEFAULT '',
long_desc varchar(16384) NOT NULL DEFAULT '',
hash binary(20) NOT NULL,
PRIMARY KEY (id_gpu),
KEY hash (hash)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE cpus (
id_cpu mediumint(8) unsigned NOT NULL auto_increment,
summary varchar(1024) NOT NULL DEFAULT '',
hash binary(20) NOT NULL,
PRIMARY KEY (id_cpu),
KEY hash (hash)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE platforms (
id_platform mediumint(8) unsigned NOT NULL auto_increment,
title varchar(32) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (id_platform),
UNIQUE KEY title (title)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE report_message_gpus (
id_msg int(10) unsigned NOT NULL,
id_gpu mediumint(8) unsigned NOT NULL,
first_report datetime NOT NULL,
latest_report datetime NOT NULL,
hits smallint(5) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (id_msg, id_gpu),
KEY `id_gpu-latest_report` (id_gpu, latest_report)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE report_message_cpus (
id_msg int(10) unsigned NOT NULL,
id_cpu mediumint(8) unsigned NOT NULL,
first_report datetime NOT NULL,
latest_report datetime NOT NULL,
hits smallint(5) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (id_msg, id_cpu),
KEY `id_cpu-latest_report` (id_cpu, latest_report)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE report_message_platforms (
id_msg int(10) unsigned NOT NULL,
id_platform mediumint(8) unsigned NOT NULL,
first_report datetime NOT NULL,
latest_report datetime NOT NULL,
hits smallint(5) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (id_msg, id_platform),
KEY `id_platform-latest_report` (id_platform, latest_report)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE report_messages
ADD COLUMN status enum('new', 'resolved', 'reoccurring') NOT NULL DEFAULT 'new',
ADD COLUMN resolved_version_value int(10) unsigned NOT NULL DEFAULT 0,
ADD INDEX status (status);
ALTER TABLE games
CHANGE COLUMN id_game id_game char(18) CHARACTER SET latin1 NOT NULL COMMENT 'Without hyphen.';
ALTER TABLE report_messages
CHANGE COLUMN id_game id_game char(18) CHARACTER SET latin1 NOT NULL COMMENT 'Without hyphen.';
ALTER TABLE versions
ADD INDEX `title-id_version` (title, id_version);
delimiter //
CREATE PROCEDURE resolve_message_kind (
a_id_msg_kind int(10) unsigned,
a_version_value int(10) unsigned
)
BEGIN
IF a_version_value = 0 THEN
SET a_version_value = (
SELECT MAX(value)
FROM versions
);
END IF;
UPDATE report_messages
SET status = 'resolved',
resolved_version_value = a_version_value
WHERE status IN ('new', 'reoccurring')
AND (resolved_version_value <= a_version_value OR status = 'new')
AND id_msg_kind = a_id_msg_kind;
END//
CREATE PROCEDURE resolve_message_id (
a_id_msg int(10) unsigned,
a_version_value int(10) unsigned
)
BEGIN
IF a_version_value = 0 THEN
SET a_version_value = (
SELECT MAX(value)
FROM versions
);
END IF;
UPDATE report_messages
SET status = 'resolved',
resolved_version_value = a_version_value
WHERE status IN ('new', 'reoccurring')
AND (resolved_version_value <= a_version_value OR status = 'new')
AND id_msg = a_id_msg;
END//
CREATE PROCEDURE resolve_message_formatted (
a_id_msg_kind int(10) unsigned,
a_formatted_message varchar(4096),
a_version_value int(10) unsigned
)
BEGIN
IF a_version_value = 0 THEN
SET a_version_value = (
SELECT MAX(value)
FROM versions
);
END IF;
UPDATE report_messages
SET status = 'resolved',
resolved_version_value = a_version_value
WHERE status IN ('new', 'reoccurring')
AND (resolved_version_value <= a_version_value OR status = 'new')
AND id_msg_kind = a_id_msg_kind
AND formatted_hash = UNHEX(SHA1(a_formatted_message))
AND formatted_message = a_formatted_message;
END//
CREATE FUNCTION fetch_cpu_ (
a_summary varchar(1024),
a_hash binary(20)
) RETURNS mediumint(8) unsigned READS SQL DATA
BEGIN
RETURN (
SELECT id_cpu
FROM cpus
WHERE summary = a_summary
AND hash = a_hash
LIMIT 1
);
END//
CREATE PROCEDURE create_cpu (
a_summary varchar(1024)
)
BEGIN
DECLARE v_id_cpu mediumint(8) unsigned;
DECLARE v_hash binary(20) DEFAULT UNHEX(SHA1(a_summary));
SET v_id_cpu = fetch_cpu_(a_summary, v_hash);
IF v_id_cpu IS NULL THEN
INSERT IGNORE INTO cpus
(summary, hash)
VALUES (a_summary, v_hash);
-- Re-select in case someone else inserted.
SET v_id_cpu = fetch_cpu_(a_summary, v_hash);
END IF;
SELECT v_id_cpu;
END//
CREATE FUNCTION fetch_platform_ (
a_title varchar(32)
) RETURNS mediumint(8) unsigned READS SQL DATA
BEGIN
RETURN (
SELECT id_platform
FROM platforms
WHERE title = a_title
LIMIT 1
);
END//
CREATE PROCEDURE create_platform (
a_title varchar(32) CHARACTER SET latin1
)
BEGIN
DECLARE v_id_platform mediumint(8) unsigned;
SET v_id_platform = fetch_platform_(a_title);
IF v_id_platform IS NULL THEN
INSERT IGNORE INTO platforms
(title)
VALUES (a_title);
-- Re-select in case someone else inserted.
SET v_id_platform = fetch_platform_(a_title);
END IF;
SELECT v_id_platform;
END//
CREATE FUNCTION fetch_gpu_ (
a_short_desc varchar(96),
a_long_desc varchar(16384),
a_hash binary(20)
) RETURNS mediumint(8) unsigned READS SQL DATA
BEGIN
RETURN (
SELECT id_gpu
FROM gpus
WHERE short_desc = a_short_desc
AND long_desc = a_long_desc
AND hash = a_hash
LIMIT 1
);
END//
CREATE PROCEDURE create_gpu (
a_short_desc varchar(96),
a_long_desc varchar(16384),
a_nickname varchar(128)
)
BEGIN
DECLARE v_id_gpu mediumint(8) unsigned;
DECLARE v_hash binary(20) DEFAULT UNHEX(SHA1(CONCAT(a_short_desc, a_long_desc)));
SET v_id_gpu = fetch_gpu_(a_short_desc, a_long_desc, v_hash);
IF v_id_gpu IS NULL THEN
INSERT IGNORE INTO gpus
(short_desc, long_desc, nickname, hash)
VALUES (a_short_desc, a_long_desc, a_nickname, v_hash);
-- Re-select in case someone else inserted.
SET v_id_gpu = fetch_gpu_(a_short_desc, a_long_desc, v_hash);
END IF;
SELECT v_id_gpu;
END//
CREATE PROCEDURE create_report_message (
a_id_msg_kind int(10) unsigned,
a_id_game char(18) CHARACTER SET latin1,
a_formatted_message varchar(4096),
a_id_version int(10) unsigned
)
BEGIN
DECLARE v_id_msg int(10) unsigned;
DECLARE v_status enum('new', 'resolved', 'reoccurring');
DECLARE v_formatted_hash binary(20) DEFAULT UNHEX(SHA1(a_formatted_message));
DECLARE v_version_value int(10) unsigned;
DECLARE v_resolved_value int(10) unsigned;
SELECT id_msg, status
INTO v_id_msg, v_status
FROM report_messages
WHERE id_msg_kind = a_id_msg_kind
AND id_game = a_id_game
AND formatted_hash = v_formatted_hash
AND formatted_message = a_formatted_message
LIMIT 1;
IF v_status = 'resolved' THEN
-- Oh well, guess it's happening again... unless this is an older version.
SET v_version_value = (
SELECT value
FROM versions
WHERE id_version = a_id_version
LIMIT 1
);
SET v_resolved_value = (
SELECT resolved_version_value
FROM report_messages
WHERE id_msg = v_id_msg
LIMIT 1
);
IF v_version_value >= v_resolved_value THEN
UPDATE report_messages
SET status = 'reoccurring'
WHERE id_msg = v_id_msg
AND resolved_version_value < v_version_value
LIMIT 1;
END IF;
ELSEIF v_id_msg IS NULL THEN
INSERT IGNORE INTO report_messages
(id_msg_kind, id_game, formatted_hash, formatted_message)
VALUES (a_id_msg_kind, a_id_game, v_formatted_hash, a_formatted_message);
SET v_id_msg = (
SELECT id_msg
FROM report_messages
WHERE id_msg_kind = a_id_msg_kind
AND id_game = a_id_game
AND formatted_hash = v_formatted_hash
AND formatted_message = a_formatted_message
LIMIT 1
);
END IF;
SELECT v_id_msg;
END//
CREATE FUNCTION fetch_report_message_kind_ (
a_message varchar(1024),
a_hash binary(20)
) RETURNS int(10) unsigned READS SQL DATA
BEGIN
RETURN (
SELECT id_msg_kind
FROM report_message_kinds
WHERE hash = a_hash
AND message = a_message
ORDER BY id_msg_kind ASC
LIMIT 1
);
END//
CREATE PROCEDURE create_report_message_kind (
a_message varchar(1024)
)
BEGIN
DECLARE v_id_msg_kind int(10) unsigned;
DECLARE v_hash binary(20) DEFAULT UNHEX(SHA1(a_message));
SET v_id_msg_kind = fetch_report_message_kind_(a_message, v_hash);
IF v_id_msg_kind IS NULL THEN
-- Unfortunately, this could create duplicates.
-- We'll always get the same (lowest id) anyway, though.
-- Can just clean them up later, rather than taking a hit for a transaction.
INSERT IGNORE INTO report_message_kinds
(message, hash)
VALUES (a_message, v_hash);
-- Re-select in case someone else inserted.
SET v_id_msg_kind = fetch_report_message_kind_(a_message, v_hash);
END IF;
SELECT v_id_msg_kind;
END//
CREATE FUNCTION fetch_game_exists_ (
a_id_game char(18) CHARACTER SET latin1
) RETURNS tinyint(1) READS SQL DATA
BEGIN
RETURN EXISTS (
SELECT id_game
FROM games
WHERE id_game = a_id_game
LIMIT 1
);
END//
CREATE PROCEDURE create_game (
a_id_game char(18) CHARACTER SET latin1,
a_title varchar(255)
)
BEGIN
DECLARE v_exists tinyint(1);
SET v_exists = fetch_game_exists_(a_id_game);
IF v_exists = 0 THEN
INSERT IGNORE INTO games
(id_game, title)
VALUES (a_id_game, a_title);
END IF;
SELECT a_id_game;
END//
CREATE FUNCTION fetch_version_ (
a_title varchar(32)
) RETURNS int(10) unsigned READS SQL DATA
BEGIN
RETURN (
SELECT id_version
FROM versions
WHERE title = a_title
LIMIT 1
);
END//
CREATE PROCEDURE create_version (
a_title varchar(32),
a_value int(10) unsigned
)
BEGIN
DECLARE v_id_version int(10) unsigned;
SET v_id_version = fetch_version_(a_title);
IF v_id_version IS NULL THEN
INSERT IGNORE INTO versions
(title, value)
VALUES (a_title, a_value);
-- Re-select in case someone else inserted.
SET v_id_version = fetch_version_(a_title);
END IF;
SELECT v_id_version;
END//
delimiter ;
ALTER TABLE report_messages
ADD INDEX id_game (id_game);
delimiter //
CREATE PROCEDURE report_message_hit (
a_id_msg int(10) unsigned,
a_id_version int(10) unsigned,
a_id_gpu mediumint(8) unsigned,
a_id_cpu mediumint(8) unsigned,
a_id_platform mediumint(8) unsigned,
a_id_config int(10) unsigned
)
BEGIN
INSERT INTO report_message_versions
(id_msg, id_version, first_report, latest_report)
VALUES (a_id_msg, a_id_version, NOW(), NOW())
ON DUPLICATE KEY UPDATE
latest_report = NOW(),
hits = hits + 1;
INSERT INTO report_message_gpus
(id_msg, id_gpu, first_report, latest_report)
VALUES (a_id_msg, a_id_gpu, NOW(), NOW())
ON DUPLICATE KEY UPDATE
latest_report = NOW(),
hits = hits + 1;
INSERT INTO report_message_cpus
(id_msg, id_cpu, first_report, latest_report)
VALUES (a_id_msg, a_id_cpu, NOW(), NOW())
ON DUPLICATE KEY UPDATE
latest_report = NOW(),
hits = hits + 1;
INSERT INTO report_message_platforms
(id_msg, id_platform, first_report, latest_report)
VALUES (a_id_msg, a_id_platform, NOW(), NOW())
ON DUPLICATE KEY UPDATE
latest_report = NOW(),
hits = hits + 1;
INSERT INTO report_message_configs
(id_msg, id_config, first_report, latest_report)
VALUES (a_id_msg, a_id_config, NOW(), NOW())
ON DUPLICATE KEY UPDATE
latest_report = NOW(),
hits = hits + 1;
END//
delimiter ;
ALTER TABLE versions
ADD INDEX `value-id_version` (value, id_version);
delimiter //
CREATE PROCEDURE resolve_message_kind_before (
a_id_msg_kind int(10) unsigned,
a_version_value int(10) unsigned
)
BEGIN
UPDATE report_messages
SET status = 'resolved',
resolved_version_value = a_version_value
WHERE status IN ('new', 'reoccurring')
AND (resolved_version_value <= a_version_value OR status = 'new')
AND id_msg_kind = a_id_msg_kind
AND id_msg NOT IN (
SELECT id_msg
FROM report_message_versions
NATURAL JOIN versions
WHERE value > a_version_value
);
END//
delimiter ;
CREATE TABLE settings (
min_version_value int(10) unsigned NOT NULL DEFAULT 0
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO settings
(min_version_value)
VALUES (0);
CREATE TABLE configs (
id_config int(10) unsigned NOT NULL auto_increment,
first_report datetime NOT NULL,
hash binary(20) NOT NULL,
PRIMARY KEY (id_config),
UNIQUE KEY (hash)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE config_settings (
id_config_setting mediumint(8) unsigned NOT NULL auto_increment,
title varchar(64) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (id_config_setting),
UNIQUE KEY (title)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE config_values (
id_config int(10) unsigned NOT NULL,
id_config_setting mediumint(8) unsigned NOT NULL,
value varchar(255) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (id_config, id_config_setting)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE report_message_configs (
id_msg int(10) unsigned NOT NULL,
id_config int(10) unsigned NOT NULL,
first_report datetime NOT NULL,
latest_report datetime NOT NULL,
hits smallint(5) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (id_msg, id_config),
KEY `id_config-latest_report` (id_config, latest_report)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
delimiter //
CREATE FUNCTION fetch_config_ (
a_hash binary(20)
) RETURNS int(10) unsigned READS SQL DATA
BEGIN
RETURN (
SELECT id_config
FROM configs
WHERE hash = a_hash
LIMIT 1
);
END//
CREATE FUNCTION fetch_config_setting_ (
a_key varchar(64) CHARACTER SET latin1
) RETURNS mediumint(8) unsigned READS SQL DATA
BEGIN
RETURN (
SELECT id_config_setting
FROM config_settings
WHERE title = a_key
LIMIT 1
);
END//
CREATE PROCEDURE create_config (
a_settings varchar(4095)
)
BEGIN
DECLARE v_id_config int(10) unsigned;
DECLARE v_hash binary(20) DEFAULT UNHEX(SHA1(a_settings));
SET v_id_config = fetch_config_(v_hash);
IF v_id_config IS NULL THEN
INSERT IGNORE INTO configs
(hash, first_report)
VALUES (v_hash, NOW());
-- Re-select in case someone else inserted.
SET v_id_config = fetch_config_(v_hash);
END IF;
SELECT v_id_config;
END//
CREATE PROCEDURE set_config_value (
a_id_config int(10) unsigned,
a_key varchar(64) CHARACTER SET latin1,
a_value varchar(255) CHARACTER SET latin1
)
BEGIN
DECLARE v_id_config_setting mediumint(8) unsigned;
SET v_id_config_setting = fetch_config_setting_(a_key);
IF v_id_config_setting IS NULL THEN
INSERT IGNORE INTO config_settings
(title)
VALUES (a_key);
-- Re-select in case someone else inserted.
SET v_id_config_setting = fetch_config_setting_(a_key);
END IF;
INSERT IGNORE INTO config_values
(id_config, id_config_setting, value)
VALUES (a_id_config, v_id_config_setting, a_value);
SELECT v_id_config_setting;
END//
delimiter ;
CREATE TABLE genres (
id_genre tinyint(3) unsigned NOT NULL auto_increment,
title varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (id_genre)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE game_genres (
id_game char(14) CHARACTER SET latin1 NOT NULL COMMENT 'Without hyphen.',
id_genre tinyint(3) unsigned NOT NULL,
hits smallint(5) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (id_game, id_genre)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE compat_ratings (
id_compat_rating tinyint(3) unsigned NOT NULL,
title varchar(255) NOT NULL DEFAULT '',
identifier varchar(32) CHARACTER SET latin1 NOT NULL DEFAULT '',
PRIMARY KEY (id_compat_rating)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO compat_ratings
(id_compat_rating, title, identifier)
VALUES (1, 'Perfect', 'perfect'),
(2, 'Playable', 'playable'),
(3, 'Ingame', 'ingame'),
(4, 'Menu/Intro', 'menu'),
(5, 'Doesn''t Boot', 'none');
CREATE TABLE report_compatibility (
id_compat int(10) unsigned NOT NULL auto_increment,
id_compat_rating tinyint(3) unsigned NOT NULL,
id_game char(14) CHARACTER SET latin1 NOT NULL COMMENT 'Without hyphen.',
id_version int(10) unsigned NOT NULL,
id_platform mediumint(8) unsigned NOT NULL,
id_gpu mediumint(8) unsigned NOT NULL,
id_cpu mediumint(8) unsigned NOT NULL,
id_config int(10) unsigned NOT NULL,
latest_report datetime NOT NULL,
graphics_stars tinyint(3) unsigned NOT NULL DEFAULT 0,
speed_stars tinyint(3) unsigned NOT NULL DEFAULT 0,
gameplay_stars tinyint(3) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (id_compat),
KEY (id_game, latest_report)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE compatibility (
id_game char(14) CHARACTER SET latin1 NOT NULL COMMENT 'Without hyphen.',
id_compat_rating tinyint(3) unsigned NOT NULL,
id_genre tinyint(3) unsigned NOT NULL,
latest_report datetime NOT NULL,
overall_stars tinyint(3) unsigned NOT NULL DEFAULT 0,
graphics_stars tinyint(3) unsigned NOT NULL DEFAULT 0,
speed_stars tinyint(3) unsigned NOT NULL DEFAULT 0,
gameplay_stars tinyint(3) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (id_game),
KEY (id_genre),
KEY (id_compat_rating),
KEY (overall_stars)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
delimiter //
CREATE PROCEDURE report_compat_hit (
a_id_compat_rating tinyint(3) unsigned,
a_id_game char(18) CHARACTER SET latin1,
a_id_version int(10) unsigned,
a_id_gpu mediumint(8) unsigned,
a_id_cpu mediumint(8) unsigned,
a_id_platform mediumint(8) unsigned,
a_id_config int(10) unsigned,
a_id_genre tinyint(3) unsigned,
a_graphics_stars tinyint(3) unsigned,
a_speed_stars tinyint(3) unsigned,
a_gameplay_stars tinyint(3) unsigned
)
BEGIN
DECLARE v_overall_stars tinyint(3) unsigned;
INSERT INTO report_compatibility
(id_compat_rating, id_game, id_version, id_platform, id_gpu, id_cpu, id_config,
latest_report, graphics_stars, speed_stars, gameplay_stars)
VALUES (a_id_compat_rating, a_id_game, a_id_version, a_id_platform, a_id_gpu, a_id_cpu, a_id_config,
NOW(), a_graphics_stars, a_speed_stars, a_gameplay_stars);
IF a_id_genre != 0 THEN
INSERT INTO game_genres
(id_game, id_genre)
VALUES (a_id_game, a_id_genre)
ON DUPLICATE KEY UPDATE
hits = hits + 1;
END IF;
SET v_overall_stars = (a_graphics_stars + a_speed_stars + a_gameplay_stars) / 3;
-- Now we need to update the compatibility average.
-- For now, replace. Smarter later, genre later.
INSERT IGNORE INTO compatibility
(id_game, id_compat_rating, id_genre, latest_report, overall_stars, graphics_stars, speed_stars, gameplay_stars)
VALUES (a_id_game, a_id_compat_rating, a_id_genre, NOW(), v_overall_stars, a_graphics_stars, a_speed_stars, a_gameplay_stars)
ON DUPLICATE KEY UPDATE
id_compat_rating = VALUES(id_compat_rating),
id_genre = IF(a_id_genre = 0, id_genre, VALUES(id_genre)),
latest_report = VALUES(latest_report),
overall_stars = VALUES(overall_stars),
graphics_stars = VALUES(graphics_stars),
speed_stars = VALUES(speed_stars),
gameplay_stars = VALUES(gameplay_stars);
END//
delimiter ;
ALTER TABLE report_message_versions
ADD INDEX `id_version-id_msg` (id_version, id_msg);
ALTER TABLE report_message_versions
ENGINE=InnoDB;
ALTER TABLE gpus
ADD COLUMN nickname varchar(128) NOT NULL DEFAULT '';
CREATE TABLE gpu_extensions (
id_gpu_ext mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
name varchar(128) NOT NULL DEFAULT '',
PRIMARY KEY (id_gpu_ext),
UNIQUE (name)
) ENGINE=MyISAM;
CREATE TABLE gpu_extension_map (
id_gpu mediumint(8) unsigned NOT NULL,
id_gpu_ext mediumint(8) unsigned NOT NULL,
PRIMARY KEY (id_gpu, id_gpu_ext)
) ENGINE=MyISAM;
delimiter //
DROP PROCEDURE IF EXISTS create_gpu//
CREATE PROCEDURE create_gpu (
a_short_desc varchar(96),
a_long_desc varchar(16384),
a_nickname varchar(128)
)
BEGIN
DECLARE existed tinyint(1) unsigned DEFAULT 1;
DECLARE v_id_gpu mediumint(8) unsigned;
DECLARE v_hash binary(20) DEFAULT UNHEX(SHA1(CONCAT(a_short_desc, a_long_desc)));
SET v_id_gpu = fetch_gpu_(a_short_desc, a_long_desc, v_hash);
IF v_id_gpu IS NULL THEN
INSERT IGNORE INTO gpus
(short_desc, long_desc, nickname, hash)
VALUES (a_short_desc, a_long_desc, a_nickname, v_hash);
-- Re-select in case someone else inserted.
SET v_id_gpu = fetch_gpu_(a_short_desc, a_long_desc, v_hash);
SET existed = 0;
END IF;
SELECT v_id_gpu, existed;
END//
CREATE FUNCTION fetch_gpu_ext_ (
a_name varchar(128)
) RETURNS mediumint(8) unsigned READS SQL DATA
BEGIN
RETURN (
SELECT id_gpu_ext
FROM gpu_extensions
WHERE name = a_name
LIMIT 1
);
END//
CREATE PROCEDURE create_gpu_extension (
a_id_gpu mediumint(8) unsigned,
a_name varchar(128)
)
BEGIN
DECLARE v_id_gpu_ext mediumint(8) unsigned;
SET v_id_gpu_ext = fetch_gpu_ext_(a_name);
IF v_id_gpu_ext IS NULL THEN
INSERT IGNORE INTO gpu_extensions
(name)
VALUES (a_name);
-- Re-select in case someone else inserted.
SET v_id_gpu_ext = fetch_gpu_ext_(a_name);
END IF;
INSERT INTO gpu_extension_map
(id_gpu, id_gpu_ext)
VALUES (a_id_gpu, v_id_gpu_ext);
SELECT v_id_gpu_ext;
END//
delimiter ;
delimiter //
CREATE PROCEDURE update_compat (
a_id_game char(18) CHARACTER SET latin1,
a_id_genre tinyint(3) unsigned
)
BEGIN
-- Smarter later, genre later.
INSERT IGNORE INTO compatibility
(id_game, id_genre, latest_report, graphics_stars, speed_stars, gameplay_stars, overall_stars, id_compat_rating)
SELECT
id_game, a_id_genre, MAX(latest_report) AS latest_report, AVG(graphics_stars), AVG(speed_stars), AVG(gameplay_stars),
(AVG(graphics_stars) + AVG(speed_stars) + AVG(gameplay_stars)) / 3 AS overall_stars,
(
SELECT id_compat_rating
FROM report_compatibility
WHERE id_game = a_id_game
GROUP BY id_compat_rating
ORDER BY COUNT(id_compat_rating) DESC
LIMIT 1
) AS id_compat_rating
FROM report_compatibility
WHERE id_game = a_id_game
ON DUPLICATE KEY UPDATE
id_compat_rating = VALUES(id_compat_rating),
id_genre = IF(a_id_genre = 0, id_genre, VALUES(id_genre)),
latest_report = VALUES(latest_report),
overall_stars = VALUES(overall_stars),
graphics_stars = VALUES(graphics_stars),
speed_stars = VALUES(speed_stars),
gameplay_stars = VALUES(gameplay_stars);
END//
DROP PROCEDURE report_compat_hit//
CREATE PROCEDURE report_compat_hit (
a_id_compat_rating tinyint(3) unsigned,
a_id_game char(18) CHARACTER SET latin1,
a_id_version int(10) unsigned,
a_id_gpu mediumint(8) unsigned,
a_id_cpu mediumint(8) unsigned,
a_id_platform mediumint(8) unsigned,
a_id_config int(10) unsigned,
a_id_genre tinyint(3) unsigned,
a_graphics_stars tinyint(3) unsigned,
a_speed_stars tinyint(3) unsigned,
a_gameplay_stars tinyint(3) unsigned
)
BEGIN
INSERT INTO report_compatibility
(id_compat_rating, id_game, id_version, id_platform, id_gpu, id_cpu, id_config,
latest_report, graphics_stars, speed_stars, gameplay_stars)
VALUES (a_id_compat_rating, a_id_game, a_id_version, a_id_platform, a_id_gpu, a_id_cpu, a_id_config,
NOW(), a_graphics_stars, a_speed_stars, a_gameplay_stars);
IF a_id_genre != 0 THEN
INSERT INTO game_genres
(id_game, id_genre)
VALUES (a_id_game, a_id_genre)
ON DUPLICATE KEY UPDATE
hits = hits + 1;
END IF;
-- Now we need to update the compatibility average.
CALL update_compat(a_id_game, a_id_genre);
END//
delimiter ;
ALTER TABLE settings
ADD COLUMN blocked_version_strings text CHARACTER SET latin1 NOT NULL DEFAULT '';
delimiter //
DROP PROCEDURE report_compat_hit//
CREATE PROCEDURE report_compat_hit (
OUT a_id_compat int(10) unsigned,
a_id_compat_rating tinyint(3) unsigned,
a_id_game char(18) CHARACTER SET latin1,
a_id_version int(10) unsigned,
a_id_gpu mediumint(8) unsigned,
a_id_cpu mediumint(8) unsigned,
a_id_platform mediumint(8) unsigned,
a_id_config int(10) unsigned,
a_id_genre tinyint(3) unsigned,
a_graphics_stars tinyint(3) unsigned,
a_speed_stars tinyint(3) unsigned,
a_gameplay_stars tinyint(3) unsigned
)
BEGIN
INSERT INTO report_compatibility
(id_compat_rating, id_game, id_version, id_platform, id_gpu, id_cpu, id_config,
latest_report, graphics_stars, speed_stars, gameplay_stars)
VALUES (a_id_compat_rating, a_id_game, a_id_version, a_id_platform, a_id_gpu, a_id_cpu, a_id_config,
NOW(), a_graphics_stars, a_speed_stars, a_gameplay_stars);
SELECT LAST_INSERT_ID() INTO a_id_compat;
IF a_id_genre != 0 THEN
INSERT INTO game_genres
(id_game, id_genre)
VALUES (a_id_game, a_id_genre)
ON DUPLICATE KEY UPDATE
hits = hits + 1;
END IF;
-- Now we need to update the compatibility average.
CALL update_compat(a_id_game, a_id_genre);
END//
delimiter ;
ALTER TABLE games
ADD COLUMN verified_title tinyint(1) unsigned NOT NULL DEFAULT 0;
delimiter //
DROP PROCEDURE IF EXISTS update_compat//
CREATE PROCEDURE update_compat (
a_id_game char(18) CHARACTER SET latin1,
a_id_genre tinyint(3) unsigned
)
BEGIN
DECLARE v_id_compat_rating tinyint(3) unsigned;
DROP TEMPORARY TABLE IF EXISTS unique_compatibility;
CREATE TEMPORARY TABLE unique_compatibility
SELECT
id_game, MAX(latest_report) AS latest_report, MIN(id_compat_rating) AS id_compat_rating,
MAX(graphics_stars) AS graphics_stars, MAX(speed_stars) AS speed_stars, MAX(gameplay_stars) AS gameplay_stars
FROM report_compatibility
GROUP BY id_game, id_version, id_platform, id_gpu, id_cpu, id_config;
SET v_id_compat_rating = (
SELECT id_compat_rating
FROM unique_compatibility
WHERE id_game = a_id_game
GROUP BY id_compat_rating
ORDER BY COUNT(id_compat_rating) DESC, id_compat_rating ASC
LIMIT 1
);
-- Smarter later, genre later.
INSERT IGNORE INTO compatibility
(id_game, id_genre, latest_report, graphics_stars, speed_stars, gameplay_stars, overall_stars, id_compat_rating)
SELECT
id_game, a_id_genre, MAX(latest_report) AS latest_report, AVG(graphics_stars), AVG(speed_stars), AVG(gameplay_stars),
(AVG(graphics_stars) + AVG(speed_stars) + AVG(gameplay_stars)) / 3 AS overall_stars,
v_id_compat_rating AS id_compat_rating
FROM unique_compatibility
WHERE id_game = a_id_game
ON DUPLICATE KEY UPDATE
id_compat_rating = VALUES(id_compat_rating),
id_genre = IF(a_id_genre = 0, id_genre, VALUES(id_genre)),
latest_report = VALUES(latest_report),
overall_stars = VALUES(overall_stars),