DEV Community

Rails Designer
Rails Designer

Posted on • Originally published at railsdesigner.com

Use Action Cable with Your Main PostgreSQL Database

This article was originally published on Rails Designer


In a recent article I wrote about broadcasting Turbo Streams without Redis. Next to using the long-available PostgreSQL adapter, there is the new Solid Cable gem.

The default installation assumes another (SQLite) database to store the โ€œmessagesโ€. While that works if you host your Rails (via something like Kamal), if you use Heroku (like I do for all my SaaS apps), this gets tricky.

I want to highlight how to install Solid Cable and use it with your primary (PostgreSQL) database.

  1. bundle add solid_cable
  2. bin/rails solid_cable:install

So far this is the default installation. Some manual work now!

  1. Create a new migration file bin/rails generate migration CreateSolidCableTables
  2. Open the newly created migration file (db/migrate/YYYYMMDDHHMMSS_create_solid_cable_messages.rb) and copy the contents of db/cable_schema.rb into it
  3. Delete the db/cable_schema.rb
  4. Update config/cable.yml to remove the just added connects_to configuration from the installation. File should look like this:
development:
  adapter: solid_cable

test:
  adapter: test

production:
  adapter: solid_cable
Enter fullscreen mode Exit fullscreen mode
  1. Update config/database.yml to remove any cable database entries, keeping only your primary database configuration (check Git to make sure!).
  2. Run bin/rails db:migrate

And that's it! You have now set up Solid Cable to use your primary database.

Top comments (0)