-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.sql
More file actions
90 lines (74 loc) · 3.03 KB
/
create.sql
File metadata and controls
90 lines (74 loc) · 3.03 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
-- 1. Activer le mode WAL (Write-Ahead Logging)
-- Indispensable sur Raspberry Pi pour éviter de corrompre la carte SD
-- et pour accélérer les écritures simultanées.
PRAGMA journal_mode=WAL;
CREATE TABLE IF NOT EXISTS matchs (
match_id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
match_type INT DEFAULT 1,
is_active BOOLEAN DEFAULT 1,
ended BOOLEAN DEFAULT 0,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_active_match
ON matchs (title)
WHERE is_active = 1 AND ended = 0;
-- Table des options de vote pour chaque sondage
CREATE TABLE IF NOT EXISTS options (
option_id INTEGER PRIMARY KEY AUTOINCREMENT,
match_id INTEGER NOT NULL,
option_text TEXT NOT NULL,
cotation FLOAT DEFAULT 1.1,
winner BOOLEAN DEFAULT 0,
FOREIGN KEY(match_id) REFERENCES matchs(match_id)
);
-- Table des votes
CREATE TABLE IF NOT EXISTS bets (
user_id TEXT NOT NULL, -- L'ID Discord de l'utilisateur
match_id INTEGER NOT NULL, -- Le sondage concerné
option_id INTEGER NOT NULL, -- Le choix de l'utilisateur
bet_value INTEGER NOT NULL, -- La somme pariée
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
-- Le moteur SQL refusera catégoriquement toute insertion
-- si la combinaison (user_id + match_id) existe déjà.
PRIMARY KEY (user_id, match_id),
FOREIGN KEY(match_id) REFERENCES matchs(match_id),
FOREIGN KEY(option_id) REFERENCES options(option_id),
FOREIGN KEY(user_id) REFERENCES users(user_id)
);
CREATE TABLE IF NOT EXISTS users (
user_id TEXT NOT NULL, -- L'ID Discord de l'utilisateur
user_name TEXT NOT NULL, --pseudo du user
balance INTEGER DEFAULT 1000,-- La somme possédée par l'utilisateur
historic_id INTEGER DEFAULT NULL, -- id du message récap dans ses dm
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, -- date de création du user
PRIMARY KEY (user_id)
);
CREATE TABLE IF NOT EXISTS logs (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
match_id INTEGER DEFAULT NULL,
user_id TEXT DEFAULT NULL,
action TEXT NOT NULL, -- Le type d'action (ex: 'PAYOUT' pour un gain, 'REFUND' pour un remboursement)
amount INTEGER DEFAULT 0, -- Le montant transféré
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(match_id) REFERENCES matchs(match_id)
);
CREATE TABLE IF NOT EXISTS match_prices (
match_id INTEGER NOT NULL,
ticker TEXT NOT NULL,
start_price FLOAT DEFAULT NULL,
end_price FLOAT DEFAULT NULL,
PRIMARY KEY (match_id),
FOREIGN KEY(match_id) REFERENCES matchs(match_id)
);
CREATE TABLE IF NOT EXISTS admin_data (
id INTEGER PRIMARY KEY,
leaderboard_id INTEGER DEFAULT NULL,
ouvert_id INTEGER DEFAULT NULL,
fermé_id INTEGER DEFAULT NULL,
finit_id INTEGER DEFAULT NULL,
channel_id INTEGER DEFAULT NULL,
forward_id INTEGER DEFAULT NULL,
timestamp DATETIME DEFAULT NULL
);
INSERT OR IGNORE INTO admin_data (id, leaderboard_id, channel_id, forward_id) VALUES (1, NULL, NULL, NULL);