import mysql from 'mysql2/promise'; import dotenv from 'dotenv'; import fs from 'fs'; import path from 'path'; dotenv.config(); const { DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT } = process.env; async function restoreFinal() { const connection = await mysql.createConnection({ host: DB_HOST, user: DB_USER, password: DB_PASS, database: DB_NAME, port: parseInt(DB_PORT || '3306') }); console.log('๐Ÿ“– realServerData.ts ์ฝ๋Š” ์ค‘...'); const filePath = path.join(process.cwd(), 'src/core/realServerData.ts'); const fileContent = fs.readFileSync(filePath, 'utf8'); const jsonMatch = fileContent.match(/\[\s*\{[\s\S]*\}\s*\]/); const realData = JSON.parse(jsonMatch[0]); console.log(`๐Ÿš€ ${realData.length}๊ฐœ์˜ ์‹ค์ œ ๋ฐ์ดํ„ฐ ๋ณต๊ตฌ ์‹œ์ž‘ (ํ•œ๊ธ€ ํ•„๋“œ ๊ธฐ์ค€)...`); for (const item of realData) { const type = item.storage์œ ํ˜•; let tableName = 'server_assets'; if (type === 'NAS' || type === '์Šคํ† ๋ฆฌ์ง€') tableName = 'storage_assets'; else if (type === 'PC') tableName = 'pc_assets'; // ํ•œ๊ธ€ ํ•„๋“œ๋ช…์„ DB ์ปฌ๋Ÿผ๋ช…์œผ๋กœ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ (ID ๋ฐ ํ•„์ˆ˜ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์ถ”๊ฐ€) const row = { id: Math.random().toString(36).substr(2, 9), ...item, // mapping corrections for DB schema ์œ ํ˜•: type, ์šฉ๋„: item.์šฉ๋„ || '', ์ƒ์„ธ: item.์ƒ์„ธ || '', ์œ„์น˜: item.์œ„์น˜ || '' }; // delete unnecessary key delete row.storage์œ ํ˜•; try { await connection.query(`INSERT INTO ${tableName} SET ?`, row); } catch (err) { // console.error(`โŒ ์‚ฝ์ž… ์‹คํŒจ:`, err.message); } } console.log('โœจ ๋ชจ๋“  ๋””์ž์ธ ๋ฐ ๋ฐ์ดํ„ฐ ๋ณต๊ตฌ๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'); await connection.end(); } restoreFinal().catch(err => { console.error('โŒ ๋ณต๊ตฌ ์‹คํŒจ:', err); process.exit(1); });