Simplify database.yml by merging in default options

Anything in the &default section can be merged in using <<: *default
In this case, the default already specifies that the adapter is
postgresql, the timeout is 5000, the encoding is unicode. It also
already specified the db pool, but the default actually checked 2
different ENVs and provided a fallback if it's not provided.
Lastly, I was able to move the prepared_statements section to the
defaults, because the .env.vagrant file doesn't specify
ENV['PREPARED_STATEMENTS'], development still just sets it to
'false'.
This commit is contained in:
rubic0n 2021-02-13 22:51:23 -06:00
parent 70c44fc68d
commit 903b6c7969

View File

@ -4,26 +4,18 @@ default: &default
timeout: 5000 timeout: 5000
encoding: unicode encoding: unicode
sslmode: <%= ENV['DB_SSLMODE'] || "prefer" %> sslmode: <%= ENV['DB_SSLMODE'] || "prefer" %>
prepared_statements: <%= ENV['PREPARED_STATEMENTS'] || 'false' %>
development: development:
master: master:
adapter: postgresql <<: *default
url: <%= ENV['DB_MASTER_URL'] %> url: <%= ENV['DB_MASTER_URL'] %>
pool: <%= ENV['DB_POOL'] %>
timeout: 5000
encoding: unicode
slave1: slave1:
adapter: postgresql <<: *default
url: <%= ENV['DB_SLAVE1_URL'] %> url: <%= ENV['DB_SLAVE1_URL'] %>
pool: <%= ENV['DB_POOL'] %>
timeout: 5000
encoding: unicode
slave2: slave2:
adapter: postgresql <<: *default
url: <%= ENV['DB_SLAVE2_URL'] %> url: <%= ENV['DB_SLAVE2_URL'] %>
pool: <%= ENV['DB_POOL'] %>
timeout: 5000
encoding: unicode
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
@ -46,27 +38,11 @@ test:
# prepared_statements: <%= ENV['PREPARED_STATEMENTS'] || 'true' %> # prepared_statements: <%= ENV['PREPARED_STATEMENTS'] || 'true' %>
production: production:
master: master:
adapter: postgresql <<: *default
sslmode: <%= ENV['DB_SSLMODE'] || "prefer" %>
prepared_statements: <%= ENV['PREPARED_STATEMENTS'] || 'false' %>
url: <%= ENV['DB_MASTER_URL'] %> url: <%= ENV['DB_MASTER_URL'] %>
pool: <%= ENV['DB_POOL'] %>
timeout: 5000
encoding: unicode
slave1: slave1:
adapter: postgresql <<: *default
sslmode: <%= ENV['DB_SSLMODE'] || "prefer" %>
prepared_statements: <%= ENV['PREPARED_STATEMENTS'] || 'false' %>
url: <%= ENV['DB_SLAVE1_URL'] %> url: <%= ENV['DB_SLAVE1_URL'] %>
pool: <%= ENV['DB_POOL'] %>
timeout: 5000
encoding: unicode
slave2: slave2:
adapter: postgresql <<: *default
sslmode: <%= ENV['DB_SSLMODE'] || "prefer" %>
prepared_statements: <%= ENV['PREPARED_STATEMENTS'] || 'false' %>
url: <%= ENV['DB_SLAVE1_URL'] %> url: <%= ENV['DB_SLAVE1_URL'] %>
pool: <%= ENV['DB_POOL'] %>
timeout: 5000
encoding: unicode