user.destroy all except one rails

# Find the user to be retained (replace 'id_to_keep' with the actual user id)
user_to_keep = User.find_by(id: 'id_to_keep')

# Destroy all users except the one to be retained
User.where.not(id: user_to_keep.id).destroy_all