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

async function assignAllDevicesToSchool1() {
  try {
    console.log('Updating all devices to school_id = 1...');
    
    const [result] = await db.execute(
      'UPDATE devices SET school_id = 1 WHERE school_id IS NULL OR school_id != 1'
    );
    
    console.log(`✅ Successfully updated ${result.affectedRows} devices to school_id = 1`);
    
    // Verify the update
    const [devices] = await db.execute('SELECT id, device_id, school_id FROM devices');
    console.log('\nCurrent device assignments:');
    devices.forEach(device => {
      console.log(`Device ${device.device_id}: school_id = ${device.school_id}`);
    });
    
  } catch (error) {
    console.error('❌ Error updating devices:', error.message);
  } finally {
    process.exit(0);
  }
}

assignAllDevicesToSchool1();