/**
 * 查询用户数据以诊断登录问题
 */
const { sequelize } = require('../config/database');
const { User } = require('../models');

(async () => {
  try {
    console.log('Connecting to DB...', {
      dialect: process.env.DB_DIALECT,
      host: process.env.DB_HOST,
      port: process.env.DB_PORT,
      database: process.env.DB_NAME,
      user: process.env.DB_USER
    });

    await sequelize.authenticate();
    console.log('✅ DB connected');

    // 查询所有用户
    const users = await User.findAll({
      attributes: { exclude: ['password'] } // 排除密码字段
    });
    
    console.log('📋 Users count:', users.length);
    users.forEach(user => {
      console.log(`- ID: ${user.id}, Username: ${user.username}, Email: ${user.email}, Status: ${user.status}, Role ID: ${user.role_id}, Last Login: ${user.last_login}`);
    });

    process.exit(0);
  } catch (err) {
    console.error('❌ Query failed:', err.message);
    process.exit(1);
  }
})();