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.
bundle add solid_cablebin/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_toconfiguration 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.
💬 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
{{comment}}