feat: modpacks 테이블 초기화 함수 추가

- db.js: initModpacksTable() 함수 추가
- server.js: 서버 시작 시 테이블 초기화 호출
- 스키마: id, name, version, minecraft_version, mod_loader, changelog, file_key, file_size, contents_json, created_at, updated_at
This commit is contained in:
caadiq 2025-12-23 16:26:59 +09:00
parent 7532bff8aa
commit e25faa498e
2 changed files with 32 additions and 1 deletions

View file

@ -78,6 +78,33 @@ const setIconCache = (key, value) => {
iconsCache[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 { export {
dbPool, dbPool,
dbPool as pool, dbPool as pool,
@ -86,4 +113,5 @@ export {
getIcons, getIcons,
getGamerules, getGamerules,
setIconCache, setIconCache,
initModpacksTable,
}; };

View file

@ -6,7 +6,7 @@ import { fileURLToPath } from "url";
import session from "express-session"; import session from "express-session";
// 모듈 import // 모듈 import
import { loadTranslations } from "./lib/db.js"; import { loadTranslations, initModpacksTable } from "./lib/db.js";
import { import {
MOD_API_URL, MOD_API_URL,
refreshData, refreshData,
@ -171,4 +171,7 @@ httpServer.listen(PORT, async () => {
// 번역 데이터 로드 // 번역 데이터 로드
await loadTranslations(); await loadTranslations();
// 모드팩 테이블 초기화
await initModpacksTable();
}); });