Use Action Cable with Your Main PostgreSQL Database

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
  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.

Get UI & Product Engineering Insights for Rails Apps (and product updates!)

Published at . Have suggestions or improvements on this content? Do reach out.

UI components for Ruby on Rails apps

$ 99 one-time
payment

Get Access
  • One-time Payment

  • Access to the Entire Library

  • Built for Ruby on Rails

  • Designed with Tailwind CSS and Enhanced with Hotwire

  • Updates for 12 months