Rails Designer
Posted on November 5, 2024
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.
bundle add solid_cable
bin/rails solid_cable:install
So far this is the default installation. Some manual work now!
- Create a new migration file
bin/rails generate migration CreateSolidCableTables
- 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
- Delete the db/cable_schema.rb
- 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
- Update config/database.yml to remove any cable database entries, keeping only your primary database configuration (check Git to make sure!).
- Run
bin/rails db:migrate
And that's it! You have now set up Solid Cable to use your primary database.
Posted on November 5, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.