Here’s an example of a bulk operation to set the trust level to 2 for all users currently at trust level 0 or 1:
This is slow, but ensures that locked trust levels aren’t changed. But it may be preferred especially when you have fewer that 1000 users
User.where(trust_level: [0, 1]).find_each do |user|
user.change_trust_level!(TrustLevel[2])
end
If there were more than 1000 users, I would have used this instead, but this would not respect locked trust levels.
DB.exec("UPDATE users SET trust_level = 2 WHERE trust_level IN (0, 1)")