Files
reason-flow/server/seeders/001_create_admin_user.js
T
2025-11-06 11:08:59 +01:00

46 lines
1.2 KiB
JavaScript

const bcrypt = require('bcryptjs');
const { User } = require('../models');
module.exports = {
up: async (queryInterface, Sequelize) => {
try {
// Create admin user
const adminPassword = process.env.ADMIN_PASSWORD || 'admin123';
const saltRounds = 12;
const passwordHash = await bcrypt.hash(adminPassword, saltRounds);
const adminUser = await User.create({
email: 'admin@reasonflow.com',
password_hash: passwordHash,
first_name: 'Admin',
last_name: 'User',
role: 'admin',
is_active: true,
preferences: {
theme: 'light',
notifications: true,
language: 'en'
}
});
console.log('✅ Admin user created:', adminUser.email);
return adminUser;
} catch (error) {
console.error('❌ Error creating admin user:', error);
throw error;
}
},
down: async (queryInterface, Sequelize) => {
try {
await User.destroy({
where: { email: 'admin@reasonflow.com' }
});
console.log('✅ Admin user removed');
} catch (error) {
console.error('❌ Error removing admin user:', error);
throw error;
}
}
};