Rails command to delete all users from my test discourse site?


#1

Can someone help me with the rails command to delete all the users from my test discourse site?

I’m deleting all the users because I imported the users from my prod instance.


(Muhlis C) #2
User.find_each(&:destroy)

Note: do not execute code above unless you know what you are doing.

To delete non-admin users:

User.where.not(admin: true).each(&:destroy)

(cpradio) #3

For the record, that will destroy every user, you may want to filter some of them, such as, those with an ID less than 1 and your own admin account.


(Muhlis C) #4

Thanks. I’ve edited my post.


(Joshua Rosenfeld) #5

Also, this should go without saying but always take a backup before running commands like this.