I find that for most actions it’s easier and a bit safer to access the rails console rather than directly interact with the database.
Or, if what you want to do is change a user’s password (oh, that’s not what you were trying to do, but this is still a fine example), do
cd /var/discourse
./launcher enter app
rake admin:create
In spite of it’s name, that rake task will allow you to do
- create a user (but it’s fine if the user exists)
- change the password (but you don’t have to)
- make the user an admin (but you don’t have to).
Have a look at Administrative Bulk Operations for some other examples.
But here are a few:
users=User.all
me=User.find_by_username ('pfaffman')
me=User.find_by_email('jay@literatecomputing.com')
UserEmail.create!(user: me, email: myotheraddress@somewhereelse.com')
posts_with_uploads=Post.where("raw like '%upload%' ")
Group.create(
name: "mygreatgroup",
automatic_membership_email_domains: 'literatecomputing.com',
primary_group: true,
title: "Literate Computing Staff",
grant_trust_level: 4,
flair_url: 'https://example.com/path.icon.png'
)