If you need to update the user preference for all of your users or a large subset of users, you can do so via the rails console.
From console, run these commands to enter the rails console for Discourse
./launcher enter app
rails c
Then, run a command that selects the set of users you wish to update.
Examples
Set the last seen date for users who have never logged in
User.where("last_seen_at IS NULL").update_all(last_seen_at: 1.week.ago)
Unset mailing list mode for all users who may have set it
Set back to the default to stop emailing these users about every new post.
UserOption.update_all(mailing_list_mode: false)
Stop sending emails to active users
Set back to the default to suppress email notifications when user is active on the site.
UserOption.update_all(email_always: true)
Enable chat for all members of the beta group
beta_group = Group.find_by_name("beta")
beta_group.users.each do |user|
UserOption.where(user_id: user.id).update_all(enable_chat: true)
end
Set preference to exclude previous replies in email notifications
UserOption.update_all(email_previous_replies: 0)
Where email_previous_replies
can have one of the these values:
- 0: always
- 1: unless previously sent
- 2: never
Related: Configure whether previous replies are included in your notification emails
Find the name of a setting
To find the name of the user setting to change, and all of its possible values, you have a few options:
- Use the data explorer plugin to inspect the
user_options
table. - Search the discourse GitHub repo. For example, to find the setting for
search for When I post in a topic, set that topic to, and you need to change thenotification_level_when_replying
user option towatching
- Setup docker to expose psql and use PGadmin