From 0b47c63ac1238843977fb6c9cfc70b0b480d9a63 Mon Sep 17 00:00:00 2001 From: Louis Mazin Date: Tue, 9 Dec 2025 20:00:43 +0100 Subject: [PATCH] finish --- database.js | 51 +-------------------------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/database.js b/database.js index 34483cd..4c44f74 100644 --- a/database.js +++ b/database.js @@ -17,54 +17,7 @@ const initDatabase = async () => { console.log('✅ Base de données connectée'); - const connection = getConnection(); - - // 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'); - } + await createTables(); console.log('✅ Tables créées/vérifiées'); } catch (error) { @@ -113,8 +66,6 @@ const createTables = async () => { INDEX idx_player_id (player_id) ) `); - - console.log('✅ Tables créées/vérifiées'); }; const generateLinkCode = async (discordId) => {