<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://adamdaniels.ca/feed.xml" rel="self" type="application/atom+xml" /><link href="https://adamdaniels.ca/" rel="alternate" type="text/html" /><updated>2026-08-21T16:17:08-04:00</updated><id>https://adamdaniels.ca/feed.xml</id><title type="html">Adam Daniels | Notes</title><subtitle>Full-stack developer building tools that matter</subtitle><author><name>Adam Daniels</name></author><entry><title type="html">Rails Multiple Databases with Environment Variables</title><link href="https://adamdaniels.ca/notes/rails-multiple-databases-environment-variables/" rel="alternate" type="text/html" title="Rails Multiple Databases with Environment Variables" /><published>2026-01-14T00:00:00-05:00</published><updated>2026-01-14T00:00:00-05:00</updated><id>https://adamdaniels.ca/notes/rails-multiple-databases-environment-variables</id><content type="html" xml:base="https://adamdaniels.ca/notes/rails-multiple-databases-environment-variables/"><![CDATA[<p>When deploying Rails with multiple databases (Solid Cable, Solid Cache, Solid Queue), you can configure each database using prefixed environment variables.</p>

<p>The naming convention is <code class="language-plaintext highlighter-rouge">{DATABASE_NAME}_DATABASE_URL</code>:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># config/database.yml</span>
<span class="na">production</span><span class="pi">:</span>
  <span class="na">primary</span><span class="pi">:</span>
    <span class="na">url</span><span class="pi">:</span> <span class="s">&lt;%= ENV["DATABASE_URL"] %&gt;</span>

  <span class="na">cache</span><span class="pi">:</span>
    <span class="na">url</span><span class="pi">:</span> <span class="s">&lt;%= ENV["CACHE_DATABASE_URL"] %&gt;</span>

  <span class="na">cable</span><span class="pi">:</span>
    <span class="na">url</span><span class="pi">:</span> <span class="s">&lt;%= ENV["CABLE_DATABASE_URL"] %&gt;</span>

  <span class="na">queue</span><span class="pi">:</span>
    <span class="na">url</span><span class="pi">:</span> <span class="s">&lt;%= ENV["QUEUE_DATABASE_URL"] %&gt;</span>
</code></pre></div></div>

<p>Then set the corresponding environment variables:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">DATABASE_URL</span><span class="o">=</span>postgres://user:pass@host/myapp_production
<span class="nv">CACHE_DATABASE_URL</span><span class="o">=</span>postgres://user:pass@host/myapp_cache
<span class="nv">CABLE_DATABASE_URL</span><span class="o">=</span>postgres://user:pass@host/myapp_cable
<span class="nv">QUEUE_DATABASE_URL</span><span class="o">=</span>postgres://user:pass@host/myapp_queue
</code></pre></div></div>

<p>This keeps credentials out of your repo. It also lets each database live on its own host, or even a different engine entirely, like SQLite for cache while primary stays on Postgres.</p>]]></content><author><name>Adam Daniels</name></author><category term="rails" /><category term="deployment" /><summary type="html"><![CDATA[When deploying Rails with multiple databases (Solid Cable, Solid Cache, Solid Queue), you can configure each database using prefixed environment variables.]]></summary></entry></feed>