From e25faa498e699fbcf410a2222ec34410950497fe Mon Sep 17 00:00:00 2001 From: caadiq Date: Tue, 23 Dec 2025 16:26:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20modpacks=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=20=EC=B4=88=EA=B8=B0=ED=99=94=20=ED=95=A8=EC=88=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - db.js: initModpacksTable() 함수 추가 - server.js: 서버 시작 시 테이블 초기화 호출 - 스키마: id, name, version, minecraft_version, mod_loader, changelog, file_key, file_size, contents_json, created_at, updated_at --- backend/lib/db.js | 28 ++++++++++++++++++++++++++++ backend/server.js | 5 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) 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(); });