const db = require('./db'); const crypto = require('crypto'); async function fixAdmin() { try { console.log('Altering table schema to include supervisor role...'); // First ensure the ENUM includes supervisor await db.query("ALTER TABLE users MODIFY COLUMN role ENUM('supervisor', 'admin', 'user') DEFAULT 'user'"); const hashedPass = crypto.createHash('sha256').update('admin123').digest('hex'); console.log('Updating admin user...'); // Update both password and role for admin const [result] = await db.query( 'UPDATE users SET password = ?, role = "supervisor" WHERE id = "admin"', [hashedPass] ); if (result.affectedRows > 0) { console.log('✅ Admin user updated to Supervisor with password admin123'); } else { console.log('⚠️ Admin user not found. Creating new admin...'); await db.query( 'INSERT INTO users (id, password, name, role, department, position) VALUES (?, ?, ?, ?, ?, ?)', ['admin', hashedPass, '시스템 관리자', 'supervisor', 'IT팀', '관리자'] ); console.log('✅ Admin user created as Supervisor with password admin123'); } } catch (err) { console.error('❌ Failed to fix admin user:', err); } finally { process.exit(); } } fixAdmin();