Change the interface language for many users via a database query?

I’m wondering if someone could help me with a support request please.

I need to update the preferences of all our users who currently have an interface language of English (US) and change them over to use English (UK) instead.

Is there a data explorer query I can craft to issue some kind of SQL UPDATE query with a where clause on it to catch only the English (US) ones?

For reference / insight… we’ve recently spent a lot of time updating all our Site texts on the English (UK) language and during testing we’ve found that anyone who signed up to our platform more than a year ago was defaulting to the old default site setting of English (US), rather than English (UK), approx 15k users need updating.

You can’t run UPDATE queries via the Data Explorer plugin because it is strictly read-only.

For bulk updates like this, use the Rails console instead:

User.where(locale: 'en').update_all(locale: 'en_GB')

For more examples of updating user preferences in bulk, refer to:

If I run this in Data Explorer:

SELECT
  u.locale,
  COUNT(*) AS user_count
FROM users u
WHERE u.active = TRUE
  AND u.locale IN ('en', 'en_GB')
GROUP BY u.locale
ORDER BY user_count DESC, u.locale

I get:

locale user_count
en_GB 19479
en 16014

I need to UPDATE the 16,014 en users to be en_GB.

And I’m not brave enough to run an update query on prod :blush:

Phew :sweat_smile:

Fantastic, thank you! :person_bowing:

Thanks @jahan_gagan

I took a DB backup first :sweat_smile:

I then ran this:

It worked perfectly:

Loading production environment (Rails 8.0.4)
discourse(prod)> User.where(locale: 'en').update_all(locale: 'en_GB')
=> 16016

And my Data Explorer query now responds with:

locale user_count
en_GB 35493

Thank you :clap: