Fix jwt-token
This commit is contained in:
61
server/seedDatabase.js
Normal file
61
server/seedDatabase.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const bcrypt = require('bcryptjs');
|
||||
const { User, Device } = 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');
|
||||
}
|
||||
|
||||
// Create a sample device if none exist
|
||||
const deviceCount = await Device.count();
|
||||
if (deviceCount === 0) {
|
||||
await Device.create({
|
||||
device_id: 1001,
|
||||
name: 'Drone Detector Alpha',
|
||||
location: 'Stockholm Central',
|
||||
geo_lat: 59.3293,
|
||||
geo_lon: 18.0686,
|
||||
is_active: true,
|
||||
detection_range: 15000, // 15km
|
||||
frequency_bands: ['2.4GHz', '5.8GHz'],
|
||||
device_type: 'RF_SCANNER',
|
||||
last_heartbeat: new Date()
|
||||
});
|
||||
|
||||
console.log('✅ Sample device created');
|
||||
} else {
|
||||
console.log('✅ Devices already exist');
|
||||
}
|
||||
|
||||
console.log('🌱 Database seeding completed');
|
||||
} catch (error) {
|
||||
console.error('❌ Database seeding failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = seedDatabase;
|
||||
Reference in New Issue
Block a user