diff --git a/backend/lib/db.js b/backend/lib/db.js index f4eb18e..eb0eead 100644 --- a/backend/lib/db.js +++ b/backend/lib/db.js @@ -78,6 +78,33 @@ const setIconCache = (key, value) => { iconsCache[key] = value; }; +/** + * 모드팩 테이블 초기화 + */ +async function initModpacksTable() { + try { + await dbPool.query(` + CREATE TABLE IF NOT EXISTS modpacks ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + version VARCHAR(50) NOT NULL, + minecraft_version VARCHAR(20), + mod_loader VARCHAR(50), + changelog TEXT, + file_key VARCHAR(500) NOT NULL, + file_size BIGINT DEFAULT 0, + contents_json LONGTEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + UNIQUE KEY unique_version (name, version) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + `); + console.log("[DB] modpacks 테이블 초기화 완료"); + } catch (error) { + console.error("[DB] modpacks 테이블 초기화 실패:", error.message); + } +} + export { dbPool, dbPool as pool, @@ -86,4 +113,5 @@ export { getIcons, getGamerules, setIconCache, + initModpacksTable, }; diff --git a/backend/server.js b/backend/server.js index 2d58392..019c39d 100644 --- a/backend/server.js +++ b/backend/server.js @@ -6,7 +6,7 @@ import { fileURLToPath } from "url"; import session from "express-session"; // 모듈 import -import { loadTranslations } from "./lib/db.js"; +import { loadTranslations, initModpacksTable } from "./lib/db.js"; import { MOD_API_URL, refreshData, @@ -171,4 +171,7 @@ httpServer.listen(PORT, async () => { // 번역 데이터 로드 await loadTranslations(); + + // 모드팩 테이블 초기화 + await initModpacksTable(); });