// 初始化管理员账号
require('dotenv').config();
const bcrypt = require('bcryptjs');
const { Admin, sequelize } = require('./models');

async function initAdmin() {
  try {
    await sequelize.sync({ force: false });
    
    const hashedPassword = bcrypt.hashSync('admin123', 10);
    await Admin.create({
      username: 'admin',
      password: hashedPassword,
      name: '管理员'
    });
    
    console.log('管理员账号创建成功');
    console.log('用户名: admin');
    console.log('密码: admin123');
    process.exit(0);
  } catch (error) {
    console.error('创建失败:', error.message);
    process.exit(1);
  }
}

initAdmin();
