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 restoreRealData() { 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'); // TypeScript νŒŒμΌμ—μ„œ JSON λ°°μ—΄ λΆ€λΆ„λ§Œ μΆ”μΆœ const jsonMatch = fileContent.match(/\[\s*\{[\s\S]*\}\s*\]/); if (!jsonMatch) { throw new Error('데이터 ν˜•μ‹μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.'); } 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' && item.μš©λ„.includes('μ„œλ²„')) { tableName = 'server_assets'; // μ„œλ²„ 역할을 ν•˜λŠ” PC } else if (type === 'PC') { tableName = 'pc_assets'; } // DB μŠ€ν‚€λ§ˆ λ§€ν•‘ const filteredRow = { id: Math.random().toString(36).substr(2, 9), corp: item.법인 || '', asset_code: item.μžμ‚°μ½”λ“œ || '', type: type === 'NAS' ? 'μŠ€ν† λ¦¬μ§€' : (type === 'PC' ? 'μ„œλ²„(PC)' : type), purpose: item.μš©λ„ || '', details: item.상세 || '', location: item.μœ„μΉ˜ || '', manager_main: item.λ‹΄λ‹Ήμž_μ • || '', manager_sub: item.λ‹΄λ‹Ήμž_λΆ€ || '', ip_address: item.IPμ£Όμ†Œ || '', remote_tool: item.원격접속 || '', server_id: item.μ„œλ²„ID || '', server_pw: item.μ„œλ²„PW || '', model_name: item.λͺ¨λΈλͺ… || '', os: item.OS || '', cpu: item.CPU || '', ram: item.RAM || '', storage1: item.SSD1 || '', storage2: item.SSD2 || '', remarks: item.IP2 ? `보쑰IP: ${item.IP2}` : '' }; try { await connection.query(`INSERT INTO ${tableName} SET ?`, filteredRow); } catch (err) { console.error(`❌ [${tableName}] μ‚½μž… μ‹€νŒ¨ (${item.μžμ‚°μ½”λ“œ}):`, err.message); } } console.log('✨ μ‹€μ œ 운영 데이터 볡ꡬ가 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.'); await connection.end(); } restoreRealData().catch(err => { console.error('❌ 볡ꡬ μ‹€νŒ¨:', err); process.exit(1); });