/** * Seed script for creating initial management users * Run this once to set up the platform admin account */ const bcrypt = require('bcryptjs'); const { ManagementUser } = require('../models'); async function createInitialManagementUser() { try { // Check if any management users exist const existingUsers = await ManagementUser.count(); if (existingUsers > 0) { console.log('✅ Management users already exist. Skipping seed.'); return; } console.log('🌱 Creating initial management user...'); // Hash the password const hashedPassword = await bcrypt.hash('admin123', 10); // Create the admin user const adminUser = await ManagementUser.create({ username: 'admin', email: 'admin@platform.local', password_hash: hashedPassword, role: 'super_admin', first_name: 'Platform', last_name: 'Administrator', is_active: true, created_by: 'system' }); console.log('✅ Initial management user created successfully:'); console.log(` Username: ${adminUser.username}`); console.log(` Email: ${adminUser.email}`); console.log(` Role: ${adminUser.role}`); console.log(` Password: admin123 (Please change this immediately!)`); console.log(''); console.log('🔐 SECURITY WARNING: Change the default password immediately!'); } catch (error) { console.error('❌ Error creating initial management user:', error); throw error; } } // If called directly, run the seed if (require.main === module) { createInitialManagementUser() .then(() => { console.log('🎉 Management user seed completed successfully'); process.exit(0); }) .catch((error) => { console.error('💥 Management user seed failed:', error); process.exit(1); }); } module.exports = { createInitialManagementUser };