Tips for deploying a Rails app with Solid Queue/Cache
injung
HOBBYOP

a month ago

Hey folks — I spent a while trying to deploy a Rails app to Railway and kept hitting issues around migrations.

I'm using Solid Queue and Solid Cache to keep the stack simple. Even after a "successful" migration, the server wouldn't boot with: "solid_queue_jobs" does not exist.

I found someone with the same problem (and they ended up creating an extra Postgres DB): https://station.railway.com/questions/rails-solid-queue-5dec0303

The key insight is, you need separate databases for Solid Cache and Solid Queue, e.g. [database_name]_cache and [database_name]_queue.

Your database.yml might look like this:

production:
  primary: &primary_production
    <<: *default
    url: <%= ENV["DATABASE_URL"] %>
    database: composify_production
  cache:
    <<: *primary_production
    database: composify_production_cache
    migrations_paths: db/cache_migrate
  queue:
    <<: *primary_production
    database: composify_production_queue
    migrations_paths: db/queue_migrate

On Railway, the default DATABASE_URL for a Postgres instance often points to a database named railway. Don't use that directly, even though the docs say something like:

DATABASE_URL: Set the value to ${{Postgres.DATABASE_PUBLIC_URL}}

Instead, set your Rails app's DATABASE_URLwithout the database name so Rails can create/use multiple DBs on the same instance:

DATABASE_URL="postgresql://${{database.PGUSER}}:${{database.PGPASSWORD}}@${{database.PGHOST}}:${{database.PGPORT}}"

With that, you can create *_cache and *_queue alongside your primary DB, and Solid Queue/Cache will boot without errors.

0 Replies

Loading...