-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
111 lines (111 loc) · 3.23 KB
/
Copy pathschema.sql
File metadata and controls
111 lines (111 loc) · 3.23 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
-- Tables --
CREATE TABLE Users (
id TEXT PRIMARY KEY,
dayPoints INTEGER,
match TEXT,
remindMinutes INTEGER,
reminded INTEGER DEFAULT 0,
matchPointsHistory TEXT
);
CREATE TABLE SupercellPlayers (
tag TEXT NOT NULL,
type INTEGER NOT NULL,
userId TEXT NOT NULL,
name TEXT NOT NULL,
notifications INTEGER DEFAULT 0,
data TEXT,
active BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (tag, type),
UNIQUE (tag, userId)
);
CREATE TABLE Predictions (
matchId TEXT NOT NULL,
userId TEXT NOT NULL REFERENCES Users(id) ON DELETE CASCADE,
prediction TEXT NOT NULL,
PRIMARY KEY (userId, matchId)
);
CREATE TABLE Reminders (
id TEXT NOT NULL,
timestamp INTEGER NOT NULL,
userId TEXT NOT NULL,
remind TEXT NOT NULL,
PRIMARY KEY (id, userId)
);
CREATE TABLE Tournaments (
name TEXT NOT NULL,
flags INTEGER NOT NULL,
game INTEGER NOT NULL,
logChannel TEXT NOT NULL,
guildId TEXT NOT NULL,
registrationMode INTEGER NOT NULL DEFAULT 0,
rounds TEXT NOT NULL,
statusFlags INTEGER NOT NULL DEFAULT 0,
team INTEGER NOT NULL DEFAULT 1,
bracketsTime INTEGER,
categoryId TEXT,
channelName TEXT,
channelsTime INTEGER,
endedCategoryId TEXT,
endedChannelName TEXT,
matchMessageLink TEXT,
minPlayers INTEGER,
maxPlayers INTEGER,
registrationChannel TEXT,
registrationChannelName TEXT,
registrationEnd INTEGER,
registrationTemplateLink TEXT,
registrationRole TEXT,
registrationStart INTEGER,
registrationMessage TEXT,
roundType INTEGER,
currentRound INTEGER,
participantCount INTEGER NOT NULL DEFAULT 0,
workflowId TEXT,
id INTEGER PRIMARY KEY AUTOINCREMENT
);
CREATE TABLE TournamentTeams (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
CREATE TABLE Participants (
tournamentId INTEGER NOT NULL REFERENCES Tournaments(id) ON DELETE CASCADE,
userId TEXT NOT NULL,
tag TEXT,
name TEXT,
team INTEGER REFERENCES TournamentTeams(id) ON DELETE CASCADE,
UNIQUE (tournamentId, tag),
FOREIGN KEY (tag, userId) REFERENCES SupercellPlayers(tag, userId) ON DELETE RESTRICT,
PRIMARY KEY (tournamentId, userId)
);
CREATE TABLE Matches (
id INTEGER,
tournamentId INTEGER NOT NULL REFERENCES Tournaments(id) ON DELETE CASCADE,
status INTEGER NOT NULL DEFAULT 0,
user1 TEXT NOT NULL,
user2 TEXT,
channelId TEXT,
result1 INTEGER,
result2 INTEGER,
PRIMARY KEY (id, tournamentId),
FOREIGN KEY (tournamentId, user1) REFERENCES Participants(tournamentId, userId) ON DELETE RESTRICT,
FOREIGN KEY (tournamentId, user2) REFERENCES Participants(tournamentId, userId) ON DELETE RESTRICT
);
-- Indexes --
CREATE INDEX SupercellPlayersNotificationsIndex ON SupercellPlayers(notifications)
WHERE notifications > 0;
CREATE INDEX SupercellPlayersIndex ON SupercellPlayers(userId, type, active, tag, name);
CREATE INDEX User1Matches ON Matches(tournamentId, user1);
CREATE INDEX User2Matches ON Matches(tournamentId, user2);
CREATE UNIQUE INDEX ChannelMatches ON Matches(channelId);
CREATE INDEX ParticipantsPlayerIndex ON Participants(tag, userId);
-- Triggers --
CREATE TRIGGER IncreaseParticipantCount
AFTER
INSERT ON Participants BEGIN
UPDATE Tournaments
SET participantCount = participantCount + 1
WHERE id = NEW.tournamentId;
END;
CREATE TRIGGER DecreaseParticipantCount
AFTER DELETE ON Participants BEGIN
UPDATE Tournaments
SET participantCount = participantCount - 1
WHERE id = OLD.tournamentId;
END;