Skip to content

Commit 0743ca2

Browse files
authored
Merge pull request rails#54765 from freerange/add-docs-for-configuring-non-primary-db-with-env-var
[ci skip] Add documentation for configuring non-primary databases using an environment variable
2 parents 96a2f03 + de9dd40 commit 0743ca2

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

guides/source/active_record_multiple_databases.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ production:
8686
replica: true
8787
```
8888

89+
Connection URLs for databases can also be configured using environment variables. The variable
90+
name is formed by concatenating the connection name with `_DATABASE_URL`. For example, setting
91+
`ANIMALS_DATABASE_URL="mysql2://username:password@host/database"` is merged into the `animals`
92+
configuration in `database.yml` in the `production` environment. See
93+
[Configuring a Database](configuring.html#configuring-a-database) for details about how the
94+
merging works.
95+
8996
When using multiple databases, there are a few important settings.
9097

9198
First, the database name for `primary` and `primary_replica` should be the same because they contain

railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ test:
4949
# production:
5050
# url: <%%= ENV["MY_APP_DATABASE_URL"] %>
5151
#
52+
<%- unless options.skip_solid? -%>
53+
# Connection URLs for non-primary databases can also be configured using
54+
# environment variables. The variable name is formed by concatenating the
55+
# connection name with `_DATABASE_URL`. For example:
56+
#
57+
# CACHE_DATABASE_URL="mysql2://cacheuser:cachepass@localhost/cachedatabase"
58+
#
59+
<%- end -%>
5260
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
5361
# for a full overview on how database connection configuration can be specified.
5462
#

railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ test:
8181
# production:
8282
# url: <%%= ENV["MY_APP_DATABASE_URL"] %>
8383
#
84+
<%- unless options.skip_solid? -%>
85+
# Connection URLs for non-primary databases can also be configured using
86+
# environment variables. The variable name is formed by concatenating the
87+
# connection name with `_DATABASE_URL`. For example:
88+
#
89+
# CACHE_DATABASE_URL="postgres://cacheuser:cachepass@localhost/cachedatabase"
90+
#
91+
<%- end -%>
8492
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
8593
# for a full overview on how database connection configuration can be specified.
8694
#

railties/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ test:
5151
# production:
5252
# url: <%%= ENV["MY_APP_DATABASE_URL"] %>
5353
#
54+
<%- unless options.skip_solid? -%>
55+
# Connection URLs for non-primary databases can also be configured using
56+
# environment variables. The variable name is formed by concatenating the
57+
# connection name with `_DATABASE_URL`. For example:
58+
#
59+
# CACHE_DATABASE_URL="trilogy://cacheuser:cachepass@localhost/cachedatabase"
60+
#
61+
<%- end -%>
5462
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
5563
# for a full overview on how database connection configuration can be specified.
5664
#

0 commit comments

Comments
 (0)