Skip to content

Commit feb2ab5

Browse files
committed
Add missing foreign keys on player_events and friends_and_foes
1 parent 7f2304e commit feb2ab5

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- Cleanup records with player_events referencing non-existing accounts
2+
DELETE player_events
3+
FROM player_events
4+
LEFT JOIN login on login.id = player_events.player_id
5+
WHERE login.id IS NULL;
6+
7+
8+
-- Add foreign key constraint for player_events -> login
9+
ALTER TABLE player_events MODIFY player_id MEDIUMINT UNSIGNED NOT NULL COMMENT 'The ID of the player that triggered this event.';
10+
11+
ALTER TABLE player_events
12+
ADD CONSTRAINT player_events_login_id_fk
13+
FOREIGN KEY (player_id) REFERENCES login (id);
14+
15+
16+
17+
-- Cleanup records with friends_and_foes referencing non-existing accounts
18+
DELETE friends_and_foes
19+
FROM friends_and_foes
20+
LEFT JOIN login ON login.id = friends_and_foes.user_id
21+
WHERE login.id IS NULL;
22+
23+
DELETE friends_and_foes
24+
FROM friends_and_foes
25+
LEFT JOIN login ON login.id = friends_and_foes.subject_id
26+
WHERE login.id IS NULL;
27+
28+
-- Add foreign key constraint for friends_and_foes -> login
29+
ALTER TABLE friends_and_foes
30+
ADD CONSTRAINT friends_and_foes_user_login_id_fk
31+
FOREIGN KEY (user_id) REFERENCES login (id);
32+
33+
ALTER TABLE friends_and_foes
34+
ADD CONSTRAINT friends_and_foes_subject_login_id_fk
35+
FOREIGN KEY (subject_id) REFERENCES login (id);
36+

test-data.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- DUMMY DATA ONLY, FOR USE IN UNIT TESTS
22

3+
DELETE FROM player_events;
34
DELETE FROM reported_user;
45
DELETE FROM moderation_report;
56
DELETE FROM teamkills;
@@ -158,8 +159,8 @@ insert into game_stats (id, startTime, gameName, gameType, gameMod, `host`, mapI
158159
values (1, NOW(), 'Test game', '0', 6, 1, 1, 0);
159160

160161
insert into friends_and_foes (user_id, subject_id, `status`)
161-
values(42, 56, 'FRIEND'),
162-
(42, 57, 'FOE');
162+
values(1, 2, 'FRIEND'),
163+
(1, 3, 'FOE');
163164

164165
insert into `mod` (id, display_name, author)
165166
VALUES (1, 'test-mod', 'baz'),

0 commit comments

Comments
 (0)