Skip to content

Instantly share code, notes, and snippets.

@mattes
Created February 12, 2021 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattes/c5e55103a2eaa7d424443d82a99600ad to your computer and use it in GitHub Desktop.
Save mattes/c5e55103a2eaa7d424443d82a99600ad to your computer and use it in GitHub Desktop.
<%
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