# User attributes

**URL:** https://meta.discourse.org/t/user-attributes/315619
**Category:** Development
**Tags:** rails-console
**Created:** [July 9, 2024, 5:21pm UTC](https://meta.discourse.org/t/user-attributes/315619 "2024-07-09T17:21:51Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![anon82911141](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anon82911141](https://meta.discourse.org/u/anon82911141)
#### Post date: [July 9, 2024, 5:21pm UTC](https://meta.discourse.org/t/user-attributes/315619/1 "2024-07-09T17:21:51Z")

</div>

Hi,

I tried running commands in `rails c` such as `User.find(1).update(ip_address: nil, topics_viewed: nil)` to update the things in this list below - however, I kept getting errors:

 ![The image shows user account details with various fields such as username, email, activity status, trust level, and associated metrics, with some sensitive information redacted in red for privacy. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/7/3/e/73e56e75aa1500ed9b8cfce92c0c88dc42498f94.png)

How would I change these values?

Thanks.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 9, 2024, 6:37pm UTC](https://meta.discourse.org/t/user-attributes/315619/2 "2024-07-09T18:37:45Z")

</div>

What errors are you getting?

Some of those things live in other tables/models. Email addresses, for example, are in their own table, so you need to update those there.

What problem are you solving?

---

<div class="post-metadata">

### Author: ![anon82911141](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anon82911141](https://meta.discourse.org/u/anon82911141)
#### Post date: [July 9, 2024, 6:55pm UTC](https://meta.discourse.org/t/user-attributes/315619/3 "2024-07-09T18:55:14Z")

</div>

Just trying to reset statistics, want to get rid of topics\_viewed, posts\_read, read\_time and last\_emailed. Not interested in user details as they can be changed using the interface, only the values that affect the user’s profile but cannot be edited.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 9, 2024, 7:08pm UTC](https://meta.discourse.org/t/user-attributes/315619/4 "2024-07-09T19:08:54Z")

</div>

They can’t be edited because they aren’t part of the user model.

There’s a model that keeps up with what topics a user has viewed (`TopicViewItem`), so you’d need to clear those (maybe `TopicViewItem.destroy_all` – no – that doesn’t work.) and then run whatever updates that. And if they were emailed, then the last time they were emailed is going to be the last time they were emailed.

There’s a `PostTiming` model that keeps up with what posts are read, and  
read time. Ah, you can search the source for `PostTiming` and find something like

```plaintext
      PostTiming.destroy_for(current_user.id, [topic_id])

```

So that’s a start. Maybe this:

```plaintext
      PostTiming.destroy_for(1, PostTiming.where(user_id: 1).pluck(:topic_id).uniq))

```

There are some `ensureconsistency` tasks that might be how to update those, but I’m not quite sure.

---

<div class="post-metadata">

### Author: ![anon82911141](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anon82911141](https://meta.discourse.org/u/anon82911141)
#### Post date: [July 9, 2024, 7:23pm UTC](https://meta.discourse.org/t/user-attributes/315619/5 "2024-07-09T19:23:56Z")

</div>

In that case, is it possible to merge an admin account via the console? I’m aware it’s not with the admin interface.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 9, 2024, 7:26pm UTC](https://meta.discourse.org/t/user-attributes/315619/6 "2024-07-09T19:26:07Z")

</div>

Just remove their admin privs and do it?

But it looks like you can do it with a rake task: [Merging user accounts](https://meta.discourse.org/t/merging-user-accounts/275288)

> [@Merging user accounts](https://meta.discourse.org/t/merging-user-accounts/275288/1):
>
> `rake users:merge['source_username','target_username']`

---

<div class="post-metadata">

### Author: ![anon82911141](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anon82911141](https://meta.discourse.org/u/anon82911141)
#### Post date: [July 9, 2024, 7:29pm UTC](https://meta.discourse.org/t/user-attributes/315619/7 "2024-07-09T19:29:37Z")

</div>

Thanks for that - not sure if it’s possible to take away the original administrator’s admin privileges though.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 11, 2024, 6:23pm UTC](https://meta.discourse.org/t/user-attributes/315619/8 "2024-07-11T18:23:15Z")

</div>

If it’s a developer (that’s set in the app.yml) then I think you’re right.

Also, I just noticed this rake task!

```
rake destroy:stats

```

> <https://github.com/discourse/discourse/blob/main/app/services/destroy_task.rb#L103-L111>

Looks like that might do what you want.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 10, 2024, 6:23pm UTC](https://meta.discourse.org/t/user-attributes/315619/9 "2024-08-10T18:23:24Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
