Setup Rails 8 w/ SQLite & Solid Cable, Cache & Queue

Let's say I want this setup:

  • SQLite

  • 4 databases:

    • primary

    • cache

    • queue

    • cable

  • I want to match development environment to productionenvironment in regards to databases.

New Rails App

rails new projectname --css=tailwindcss --skip-kamal --skip-ci

After initial creation, you should have:

These schemas with definitions for tables for eacH:

  • db/cable_schema.rb

  • db/cache_schema.rb

  • db/queue_schema.rb

Nothing in /storage directory yet (databases haven't been created yet).

Before you create databases, first setup database.yml:

Database.yml

If you also have a staging environment, then copy the production block to a staging block.

Create the 4 databases

This should create 4 sqlite databases in storage folder:

  • storage/development.sqlite3

  • storage/development_cable.sqlite3

  • storage/development_cache.sqlite3

  • storage/development_queue.sqlite3

Run the first migration

Note: You don't yet have the migration folders inside of db/ folder and you don't have any migration files yet. That's OK.

The first time you run rails db:migrate, it should load the schemas for the 3 solid databases (queue, cable, cache).

Connect to each database using TablePlus

In TablePlus, create a new connection using SQLite. Simply browse for the sqlite folder in the storage directory, then connect.

You should expect to see the necessy tables for each solid database (like the tables for solid queue etc.).

Creating migrations in each database

By default, when running rails g migration ...this will create a migration file in db/migratefolder.

As of this writing, I'm unaware of a way to generate migration files in the other files, so if you need to migrate tables in any of the other 3 tables, then you have to create the migration file normally, then manually move it out of the db/migrate folder and into the appropropriate folder. For example, if migrating something in the solid queue database, move the migration to the db/queue_migration folder.

To run migrations in a specific database, append it to the command. Examples:


Last updated