Skip to content

Instantly share code, notes, and snippets.

@mattes
Created Feb 12, 2021
Embed
What would you like to do?
<%
branch = `git rev-parse --abbrev-ref HEAD`.strip rescue ENV.fetch("RAILS_DATABASE_SUFFIX", "master")
branch = branch.underscore.gsub(/[\.\/\-]/, '_')
%>
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>
host: <%= ENV.fetch("RAILS_DATABASE_HOST", "127.0.0.1") %>
port: <%= ENV.fetch("RAILS_DATABASE_PORT", 5432) %>
username: <%= ENV.fetch("RAILS_DATABASE_USERNAME", "postgres") %>
password: <%= ENV.fetch("RAILS_DATABASE_PASSWORD", "") %>
timeout: 5000
prepared_statements: true # never set to false or be vulnerable to SQLi
statement_limit: 1000
development:
<<: *default
database: <%= ENV.fetch("RAILS_DATABASE", "rails") %>_development_<%= branch %>
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: <%= ENV.fetch("RAILS_DATABASE", "rails") + "_test" %>
production:
<<: *default
database: <%= ENV.fetch("RAILS_DATABASE", "rails") %>
host: /cloudsql/<%= ENV.fetch("RAILS_DATABASE_INSTANCE_NAME", "") %>
password: <%= Rails.application.credentials.dig(:database, :password) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment