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

async function fixSchoolUsers() {
  try {
    // Update school users with proper school_id
    await db.execute(
      'UPDATE users SET school_id = 1 WHERE email = ? AND user_type = ?',
      ['principal@school.com', 'school']
    );
    
    await db.execute(
      'UPDATE users SET school_id = 2 WHERE email = ? AND user_type = ?',
      ['school@test.com', 'school']
    );
    
    console.log('Updated school user assignments');
    
    // Check current assignments
    const [users] = await db.execute(
      'SELECT id, email, user_type, school_id FROM users WHERE user_type IN ("school", "admin")'
    );
    
    console.log('Current user assignments:');
    console.table(users);
    
    process.exit(0);
  } catch (error) {
    console.error('Error:', error);
    process.exit(1);
  }
}

fixSchoolUsers();