const mysql = require('mysql2/promise');
require('dotenv').config();

async function checkTables() {
  const connection = await mysql.createConnection({
    host: process.env.DB_HOST || 'localhost',
    user: process.env.DB_USER || 'root',
    password: process.env.DB_PASSWORD || '',
    database: process.env.DB_NAME || 'sts_v2'
  });

  try {
    console.log('Checking existing tables...');
    
    const [tables] = await connection.execute('SHOW TABLES');
    console.log('📋 Existing tables:');
    tables.forEach(table => {
      console.log(`  - ${Object.values(table)[0]}`);
    });

    // Check children table structure
    try {
      const [children] = await connection.execute('SELECT COUNT(*) as count FROM children');
      console.log(`\n👥 Children table has ${children[0].count} records`);
    } catch (error) {
      console.log('\n❌ Children table does not exist');
    }

    // Check device_locations table
    try {
      const [locations] = await connection.execute('SELECT COUNT(*) as count FROM device_locations');
      console.log(`📍 Device_locations table has ${locations[0].count} records`);
    } catch (error) {
      console.log('❌ Device_locations table does not exist');
    }

  } catch (error) {
    console.error('Error checking tables:', error);
  } finally {
    await connection.end();
  }
}

checkTables();