const db = require('./config/database');

async function testDatabase() {
  try {
    console.log('Testing database connection...');
    
    // Test connection
    const [result] = await db.execute('SELECT 1 as test');
    console.log('Database connection successful:', result);
    
    // Check if users table exists
    const [tables] = await db.execute('SHOW TABLES LIKE "users"');
    console.log('Users table exists:', tables.length > 0);
    
    // Check table structure
    const [columns] = await db.execute('DESCRIBE users');
    console.log('Table structure:');
    columns.forEach(col => console.log(`- ${col.Field} (${col.Type})`));
    
    // Check users in table
    const [users] = await db.execute('SELECT * FROM users LIMIT 2');
    console.log('Sample user data:', users);
    
  } catch (error) {
    console.error('Database error:', error.message);
  } finally {
    process.exit();
  }
}

testDatabase();