const { Sequelize } = require('sequelize');

// 测试连接到 nxxmdata 数据库
const sequelize = new Sequelize({
  dialect: 'mysql',
  host: '129.211.213.226',
  port: 9527,
  database: 'nxxmdata',
  username: 'root',
  password: 'aiotAiot123!',
  logging: console.log,
  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000
  }
});

async function test() {
  console.log('测试连接到 nxxmdata 数据库...');
  
  try {
    await sequelize.authenticate();
    console.log('✅ 连接 nxxmdata 数据库成功！');
    
    // 列出所有表
    const [tables] = await sequelize.query('SHOW TABLES');
    console.log('数据库中的表:', tables.length);
    
    // 检查是否有 users 表
    const [userTables] = await sequelize.query("SHOW TABLES LIKE 'users'");
    if (userTables.length > 0) {
      console.log('✅ 找到 users 表');
      
      // 查询用户数据
      const [users] = await sequelize.query('SELECT id, username, email FROM users LIMIT 5');
      console.log('用户数据:', users);
    } else {
      console.log('❌ 没有找到 users 表');
    }
    
    await sequelize.close();
    process.exit(0);
  } catch (error) {
    console.error('❌ 连接失败:', error.message);
    process.exit(1);
  }
}

test();

