From defb45df754d683b80bb5f7aa5b4b15797b38603 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Mon, 18 May 2026 10:16:20 -0500 Subject: [PATCH] Use a single database for primary, cache, queue, cable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rails 8 ships database.yml with four separately-configured roles in production (primary, cache, queue, cable) so Solid Cache, Solid Queue, and Solid Cable can each live in their own database. The default already points all four roles at the same DATABASE_URL with separate migration paths — sharing one Render Postgres saves money but keeps the conceptual overhead of four config blocks, three empty stub schema files, and three nonexistent migration directories (db/cache_migrate, db/queue_migrate, db/cable_migrate). The migrations actually live in db/migrate/ and db/schema.rb already contains all the SC/SQ/SCable tables, so the multi-role config was purely cosmetic. Collapse to one role for student projects on Render's free tier: - config/database.yml: replace the four-role production block with a single `<<: *default` + `url:` pair. - config/cache.yml: drop `database: cache` so SolidCache::Record inherits ApplicationRecord's connection. - config/cable.yml: drop the `connects_to` block so SolidCable inherits the primary connection. - Delete db/cable_schema.rb, db/cache_schema.rb, db/queue_schema.rb; they were empty (`version: 0` stubs) and only matter when each role has its own database. Verified with `RAILS_ENV=production bin/rails runner` that ApplicationRecord, SolidQueue::Record, SolidCache::Record, and SolidCable::Record all bind to the `primary` config. The same single-DB pattern is already in production on aplace.app and has been stable since the async-mode rollout. --- config/cable.yml | 3 --- config/cache.yml | 1 - config/database.yml | 15 ++------------- db/cable_schema.rb | 17 ----------------- db/cache_schema.rb | 17 ----------------- db/queue_schema.rb | 17 ----------------- 6 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 db/cable_schema.rb delete mode 100644 db/cache_schema.rb delete mode 100644 db/queue_schema.rb diff --git a/config/cable.yml b/config/cable.yml index b9adc5a..4f8054a 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -10,8 +10,5 @@ test: production: adapter: solid_cable - connects_to: - database: - writing: cable polling_interval: 0.1.seconds message_retention: 1.day diff --git a/config/cache.yml b/config/cache.yml index 19d4908..ae55ceb 100644 --- a/config/cache.yml +++ b/config/cache.yml @@ -12,5 +12,4 @@ test: <<: *default production: - database: cache <<: *default diff --git a/config/database.yml b/config/database.yml index 5bb10df..f0c2322 100644 --- a/config/database.yml +++ b/config/database.yml @@ -81,16 +81,5 @@ test: # for a full overview on how database connection configuration can be specified. # production: - primary: &primary_production - <<: *default - url: <%= ENV["DATABASE_URL"] %> - # Share the same database for cache, queue, and cable (saves connections/memory) - cache: - <<: *primary_production - migrations_paths: db/cache_migrate - queue: - <<: *primary_production - migrations_paths: db/queue_migrate - cable: - <<: *primary_production - migrations_paths: db/cable_migrate + <<: *default + url: <%= ENV["DATABASE_URL"] %> diff --git a/db/cable_schema.rb b/db/cable_schema.rb deleted file mode 100644 index 4d004c3..0000000 --- a/db/cable_schema.rb +++ /dev/null @@ -1,17 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema[8.0].define(version: 0) do - # These are extensions that must be enabled in order to support this database - enable_extension "pg_catalog.plpgsql" - -end diff --git a/db/cache_schema.rb b/db/cache_schema.rb deleted file mode 100644 index 4d004c3..0000000 --- a/db/cache_schema.rb +++ /dev/null @@ -1,17 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema[8.0].define(version: 0) do - # These are extensions that must be enabled in order to support this database - enable_extension "pg_catalog.plpgsql" - -end diff --git a/db/queue_schema.rb b/db/queue_schema.rb deleted file mode 100644 index 4d004c3..0000000 --- a/db/queue_schema.rb +++ /dev/null @@ -1,17 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema[8.0].define(version: 0) do - # These are extensions that must be enabled in order to support this database - enable_extension "pg_catalog.plpgsql" - -end