Change chat channel linked category in Rails console?

Update:
I figured out my solution and sharing it here since it might help somebody.

Disclaimer:
You need access to your server and it helps if you understand what you’re doing. If not, I recommend getting help from somebody who knows servers and Ruby on Rails.
Also be mindful: Changing data in a running database could cause problems.

Steps:
First access your server. Once you’re there become a root user. Navigate to the Discourse container and enter it:

cd /var/discourse
./launcher enter app

Once inside the container open the Rails console:

rails c

Now in your browser find the chat channel slug. You can find it inside the URL e.g. when you open the chat channel in full screen mode:
https://my-example-forum.com/chat/c/cat-pictures/17

In the Rails console get the chat channel object you want and save it in a variable:

chat = Chat::Channel.find_by(slug: "cat-pictures")

If now you just type the variable chat and hit enter you can see the object and all its attributes. One of it is chatable_id. There you can see the ID of the category the chat channel is linked to. The chatable_id could be set to 5 for example.

We can change this chatable_id to the ID of the category you want the chat channel to correspond to. You can find this ID in the URL of the category in the browser:
https://my-example-forum.com/c/cats/9

Now that you know the desired category ID you can adjust the category linked to the chat channel:

chat.chatable_id=9
chat.save

I hope this helps.


Might also be relevant for How change a Chat Channel's category that it's linked to

1 Like