# (Obsolete) Set category tracking level defaults historically

**URL:** https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165
**Category:** Self-Hosting
**Tags:** how-to
**Created:** [2016年十一月21日 00:45 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165 "2016-11-21T00:45:27Z")
**Posts on this page:** 20
**Page:** 3

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2018年十一月29日 19:48 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/46 "2018-11-29T19:48:22Z")

</div>

It looks like you’re typing `%`? Don’t 😉. That’s just supposed to be an indication that you’re in the rails console instead of the docker container. I’ll edit the OP to be clearer.

Edit: OP edited.

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十一月29日 20:41 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/47 "2018-11-29T20:41:02Z")

</div>

Thanks. Rookie error on my part 😃

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2018年十一月29日 20:44 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/48 "2018-11-29T20:44:56Z")

</div>

No worries at all. We all start from the beginning at some point.

Is the guide clearer now?

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十一月29日 20:54 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/49 "2018-11-29T20:54:32Z")

</div>

> [@jomaxro](#):
>
> Is the guide clearer now?

Oh it makes total sense. Thanks

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十一月29日 21:24 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/50 "2018-11-29T21:24:57Z")

</div>

Actually… I’m stuck on the query. I need to update category ID 1 to notification level of regular (1).  
From rails… I’m typing

`User.exec_sql("INSERT INTO category_users(category_id, user_id, notification_level) SELECT 1, u.id, 1 FROM users u LEFT JOIN category_users cu ON cu.category_id = 1 AND cu.user_id = u.id WHERE cu.user_id IS NULL;")`

I get response

`<PG::Result:0x000055fadb534428 status=PGRES_COMMAND_OK ntuples=0 nfields=0 cmd_tuples=0>`

Via the GUI/forums, it looks like it hasn’t changed.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2018年十一月29日 21:30 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/51 "2018-11-29T21:30:28Z")

</div>

Going to call in an assist here from @sam, PostgreSQL isn’t my area of expertise.

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十二月10日 10:10 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/52 "2018-12-10T10:10:10Z")

</div>

Circling back to see if anyone has ideas on where I’m going wrong with my sql query?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2018年十二月10日 15:20 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/54 "2018-12-10T15:20:12Z")

</div>

The query you tried will only update the tracking level IF the user isn’t already tracking/watching/muting a category. It sounds like you want to **remove** any users that are watching a category.

If that’s correct, try running this on the rails console. It will find all users that are ‘watching’ the category with id=5, and set them to “regular”:

```plaintext
CategoryUser.where(notification_level: CategoryUser.notification_levels[:watching], category_id: 5).update_all(notification_level: CategoryUser.notification_levels[:regular])

```

⚠ As always, make sure to take a backup before running anything on the console - the smallest typo can have massive consequences!

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十二月10日 19:47 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/55 "2018-12-10T19:47:06Z")

</div>

Thanks David. I must have misunderstood the purpose of the query. I thought it was to update (ie lower the subscription level) for all users UNLESS they explicitly set it themselves vs it being assigned via the setting in admin panel.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2018年十二月10日 19:50 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/56 "2018-12-10T19:50:24Z")

</div>

> [@SouperC](#):
>
> for all users UNLESS they explicitly set it themselves

The more precise definition here is “for all users UNLESS it has already been set”. We don’t have any way of knowing whether a user set it themselves, or it was automatically set by the admin panel default.

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十二月10日 19:54 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/57 "2018-12-10T19:54:59Z")

</div>

> [@david](#):
>
> We don’t have any way of knowing whether a user set it themselves, or it was automatically set by the admin panel default

That makes sense because when I (thought I) saw that, I thought “well that’s impressive that we have that granularity”

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十二月11日 03:27 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/58 "2018-12-11T03:27:22Z")

</div>

Not to be a pest, but I’m still struggling with this, getting a syntax error when I run this query…

```
[4] pry(main)> User.exec_sql("INSERT INTO CategoryUser.where(notification_level: CategoryUser.notification_levels[:watching], category_id: 1).update_all(notification_level: CategoryUser.notification_levels[:regular];")

PG::SyntaxError: ERROR: syntax error at or near ":"
LINE 1: INSERT INTO CategoryUser.where(notification_level: CategoryU...

```

Any ideas on what I’m overlooking?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2018年十二月11日 07:51 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/59 "2018-12-11T07:51:02Z")

</div>

Sorry, I should have been clearer there. The command I shared does not need to be run inside “exec\_sql”. It can just be run directly on the rails console.

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十二月11日 22:39 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/60 "2018-12-11T22:39:01Z")

</div>

Sorry to spam the topic with this more rudimentary stuff. I’m still having difficulties

From the rails console (at least I think it is)

> /var/discourse# ./launcher rails c  
> /var/discourse# CategoryUser.where(notification\_level: CategoryUser.notification\_levels[:watching], category\_id: 1).update\_all(notification\_level: CategoryUser.notification\_levels[:regular])
> 
> _bash: syntax error near unexpected token `notification\_level:’_

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018年十二月11日 22:42 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/61 "2018-12-11T22:42:33Z")

</div>

> [@SouperC](#):
>
> **bash** : syntax error near unexpected token `notification\_level:’

You are missing a:

`rails c` before running the command. You want to be in Ruby not in Bash.

---

<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: [2018年十二月12日 01:50 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/62 "2018-12-12T01:50:03Z")

</div>

You need to run that inside the container.

```
./launcher enter app

```

Before the rails command

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [2018年十二月12日 02:25 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/63 "2018-12-12T02:25:55Z")

</div>

Thanks Jay. Yeah I figured that out while I was working on it today. The trigger being when I was prompted to install rails 😂

I got this to work today, checked a few accounts via impersonate and it looks like we’ll no longer be spamming our members with 100emails a day (nor paying to send them)

Thanks all

James

---

<div class="post-metadata">

### Author: ![barreeeiroo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barreeeiroo/32/165264_2.png) [@barreeeiroo](https://meta.discourse.org/u/barreeeiroo)
#### Post date: [2019年八月8日 19:25 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/64 "2019-08-08T19:25:19Z")

</div>

我想这需要一些时间才能完成，对吧？  
因为命令输出是即时的，结果如下：  
`#<PG::Result:0x000055e37f159100 status=PGRES_COMMAND_OK ntuples=0 nfields=0 cmd_tuples=8428>`  
完成可能需要多久？因为我检查了一个用户资料，发现它仍在关注该类别。

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2019年八月8日 19:32 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/65 "2019-08-08T19:32:05Z")

</div>

这应该几乎是瞬间完成的。该输出显示已更改 8,428 条记录。我假设这是您论坛的用户数量？建议您再次确认是否正确设置了类别 ID 和通知级别 ID。

---

<div class="post-metadata">

### Author: ![barreeeiroo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barreeeiroo/32/165264_2.png) [@barreeeiroo](https://meta.discourse.org/u/barreeeiroo)
#### Post date: [2019年八月10日 00:54 UTC](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165/66 "2019-08-10T00:54:20Z")

</div>

那不是我要找的查询 🤦‍♂️

这个可以工作：

```plaintext
CategoryUser.where(notification_level: CategoryUser.notification_levels[:watching], category_id: 29).update_all(notification_level: CategoryUser.notification_levels[:regular])

```

_就是 @david 上面发布的那个_

[上一頁](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165.md?page=2)

[下一頁](https://meta.discourse.org/t/obsolete-set-category-tracking-level-defaults-historically/53165.md?page=4)
