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

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.

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)

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.

2 Likes

Thanks. I’ve edited my post.

1 Like

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

2 Likes