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 app (via something like Kamal), if you use Heroku (like I do for most my SaaS’), 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.

Product-minded Rails notes

Once a month: straightforward notes on improving UX in Rails—what to simplify, what to measure, and UI/frontend changes that move real usage.

Over to you…

What did you like about this article? Learned something knew? Found something is missing or even broken? 🫣 Let me (and others) know!

Comments are powered by Chirp Form

Want to read me more?