require('dotenv').config();
const { sequelize, testConnection } = require('./config/database');

async function test() {
  console.log('测试数据库连接...');
  console.log('数据库配置:');
  console.log('- Host:', process.env.DB_HOST || '129.211.213.226');
  console.log('- Port:', process.env.DB_PORT || 9527);
  console.log('- Database:', process.env.DB_DATABASE || 'insurance_data');
  console.log('- User:', process.env.DB_USER || 'root');
  console.log('');
  
  try {
    await sequelize.authenticate();
    console.log('✅ 数据库连接成功！');
    
    // 测试查询
    const [results] = await sequelize.query('SELECT 1 as test');
    console.log('✅ 测试查询成功:', results);
    
    process.exit(0);
  } catch (error) {
    console.error('❌ 数据库连接失败:');
    console.error('错误信息:', error.message);
    console.error('错误详情:', error);
    process.exit(1);
  }
}

test();

