const mysql = require('mysql2/promise');

async function checkTableStructure() {
  try {
    // 创建数据库连接
    const connection = await mysql.createConnection({
      host: '129.211.213.226',
      port: 9527,
      user: 'root',
      password: 'aiotAiot123!',
      database: 'insurance_data'
    });

    console.log('✅ 数据库连接成功');

    // 查看devices表结构
    console.log('\n📋 devices表结构:');
    const [devicesColumns] = await connection.execute('DESCRIBE devices');
    console.table(devicesColumns);

    // 查看device_alerts表结构
    console.log('\n📋 device_alerts表结构:');
    const [alertsColumns] = await connection.execute('DESCRIBE device_alerts');
    console.table(alertsColumns);

    await connection.end();
    console.log('\n✅ 检查完成');

  } catch (error) {
    console.error('❌ 检查表结构失败:', error);
  }
}

if (require.main === module) {
  checkTableStructure().then(() => {
    process.exit(0);
  }).catch(error => {
    console.error('❌ 脚本执行失败:', error);
    process.exit(1);
  });
}

module.exports = checkTableStructure;