const bcrypt = require('bcryptjs'); const { User, Device, AlertRule } = require('./models'); async function seedDatabase() { try { console.log('🌱 Seeding database...'); // Check if admin user exists const existingAdmin = await User.findOne({ where: { username: 'admin' } }); if (!existingAdmin) { // Create default admin user const adminPassword = await bcrypt.hash('admin123', 10); await User.create({ username: 'admin', email: 'admin@dronedetection.local', password_hash: adminPassword, first_name: 'System', last_name: 'Administrator', role: 'admin', is_active: true, sms_alerts_enabled: false, email_alerts_enabled: false, timezone: 'Europe/Stockholm' }); console.log('✅ Admin user created (username: admin, password: admin123)'); } else { console.log('✅ Admin user already exists'); } // Check if tumanovsky user exists const existingTumanovsky = await User.findOne({ where: { username: 'tumanovsky' } }); if (!existingTumanovsky) { // Create tumanovsky admin user const tumanovskyPassword = await bcrypt.hash('tumanovsky', 10); await User.create({ username: 'tumanovsky', email: 'tumanovsky@dronedetection.local', password_hash: tumanovskyPassword, first_name: 'Tumanovsky', last_name: 'Admin', role: 'admin', is_active: true, sms_alerts_enabled: true, email_alerts_enabled: true, timezone: 'Europe/Stockholm' }); console.log('✅ Tumanovsky admin user created (username: tumanovsky, password: tumanovsky)'); } else { console.log('✅ Tumanovsky user already exists'); } // Create sample devices if none exist const deviceCount = await Device.count(); if (deviceCount === 0) { // REMOVED: Automatic device creation // No longer creating sample devices automatically console.log('📝 No sample devices created - add devices manually through the UI'); } else { console.log('✅ Devices already exist'); } // Get admin user for alert rules const adminUser = await User.findOne({ where: { username: 'admin' } }); // Create location-specific alert rules const alertRuleCount = await AlertRule.count(); if (alertRuleCount === 0) { // REMOVED: Automatic alert rule creation // No longer creating sample alert rules automatically console.log('📝 No sample alert rules created - add alert rules manually through the UI'); } else { console.log('✅ Alert rules already exist'); } console.log('🌱 Database seeding completed'); } catch (error) { console.error('❌ Database seeding failed:', error); throw error; } } module.exports = seedDatabase;