Bulk Deactivate Users from Bounce Score


#1

I’m trying to deactivate bulk users based on their bounce_score.
I used @pfaffman’s example as a reference (Bulk deactivation of inactive users)

cd /var/discourse
./launcher enter app
rails c
User.where("last_seen_at < '2016-01-01'").update_all(active: false)
exit
exit

So I tried (and some other variations):

User.where(“bounce_score = 4”).update_all(active: false)

And get the error:

SyntaxError: unexpected tIDENTIFIER, expecting ')'
...er.where(“bounce_score = 4”).update_all(active: false)

Anyone know what is wrong with this? Would appreciate it!


(Jay Pfaffman) #2

Here you have “smart quotes” rather than plain old quotes. I think that might be the problem.


(Régis Hanol) #3

Also, the bounce_score column is on the UserStat table not on the User table.


#4

Thanks @pfaffman & @zogstrip! Really appreciate it.

Seemed to execute fine after making both changes.

UserStat.where("bounce_score = 4").update_all(active: false)

It doesn’t seem to be updating the users with a bounce score of 4 to deactivated however. I believe this is because ‘active’ is in the User table and now the command is using the UserStat table.

I’ve tried some variations attempting to change the table in the last part of the command, but don’t want to stray too far incase I accidentally deactivate all users or something.

If anyone knows how to fix this you’d be a real life saver!