finish
This commit is contained in:
parent
b722f2333c
commit
0b47c63ac1
51
database.js
51
database.js
@ -17,54 +17,7 @@ const initDatabase = async () => {
|
|||||||
|
|
||||||
console.log('✅ Base de données connectée');
|
console.log('✅ Base de données connectée');
|
||||||
|
|
||||||
const connection = getConnection();
|
await createTables();
|
||||||
|
|
||||||
// Table pour les codes de liaison temporaires
|
|
||||||
await connection.execute(`
|
|
||||||
CREATE TABLE IF NOT EXISTS link_codes (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
discord_id VARCHAR(20) NOT NULL,
|
|
||||||
code VARCHAR(6) NOT NULL UNIQUE,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
expires_at TIMESTAMP NOT NULL,
|
|
||||||
used BOOLEAN DEFAULT FALSE,
|
|
||||||
INDEX idx_code (code),
|
|
||||||
INDEX idx_discord_id (discord_id)
|
|
||||||
)
|
|
||||||
`);
|
|
||||||
|
|
||||||
// Table pour les liaisons confirmées
|
|
||||||
await connection.execute(`
|
|
||||||
CREATE TABLE IF NOT EXISTS user_links (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
discord_id VARCHAR(20) NOT NULL UNIQUE,
|
|
||||||
discord_username VARCHAR(100) NOT NULL,
|
|
||||||
steam_id VARCHAR(50) NOT NULL,
|
|
||||||
player_id VARCHAR(50),
|
|
||||||
palworld_username VARCHAR(100) NOT NULL,
|
|
||||||
linked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
INDEX idx_discord_id (discord_id),
|
|
||||||
INDEX idx_steam_id (steam_id),
|
|
||||||
INDEX idx_player_id (player_id)
|
|
||||||
)
|
|
||||||
`);
|
|
||||||
|
|
||||||
// Migration: ajouter la colonne lastConnection si elle n'existe pas (syntaxe MySQL)
|
|
||||||
const [columns] = await connection.execute(`
|
|
||||||
SELECT COLUMN_NAME
|
|
||||||
FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = ?
|
|
||||||
AND TABLE_NAME = 'user_links'
|
|
||||||
AND COLUMN_NAME = 'lastConnection'
|
|
||||||
`, [process.env.DB_NAME]);
|
|
||||||
|
|
||||||
if (columns.length === 0) {
|
|
||||||
await connection.execute(`
|
|
||||||
ALTER TABLE user_links
|
|
||||||
ADD COLUMN lastConnection TIMESTAMP NULL DEFAULT NULL
|
|
||||||
`);
|
|
||||||
console.log('✅ Colonne lastConnection ajoutée');
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('✅ Tables créées/vérifiées');
|
console.log('✅ Tables créées/vérifiées');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -113,8 +66,6 @@ const createTables = async () => {
|
|||||||
INDEX idx_player_id (player_id)
|
INDEX idx_player_id (player_id)
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
console.log('✅ Tables créées/vérifiées');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateLinkCode = async (discordId) => {
|
const generateLinkCode = async (discordId) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user