From e8fb17ca784760c3063f737511658c7fe025e45e Mon Sep 17 00:00:00 2001 From: Alexis Hope Date: Wed, 24 Feb 2021 09:41:34 +1100 Subject: [PATCH] Update database config (#11308) --- .env_sample | 15 +++++++++++++++ .travis.yml | 5 ++++- config/database.yml | 24 +++++++++++------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.env_sample b/.env_sample index a5fd1c47f..64decff4d 100644 --- a/.env_sample +++ b/.env_sample @@ -40,6 +40,21 @@ export OPENRESTY_URL="" # SSL config export FORCE_SSL_IN_RAILS="not applicable in dev" +# Postgres DB +export DATABASE_NAME="Forem_development" # Used when creating a db instance `rails db:create` +export DATABASE_URL="postgresql://localhost:5432/$DATABASE_NAME" # This takes precedence over `DATABASE_NAME` if they don't match +export RAILS_MAX_THREADS=5 # Specifies the number of Puma threads +export WEB_CONCURRENCY=2 # Specifies the number of `workers` to boot in clustered mode. +export DATABASE_POOL_SIZE=5 # The number of concurrent connections to Postgres. If unset the value of RAILS_MAX_THREADS will be used in it's place. +export DATABASE_NAME_TEST=Forem_test +export DATABASE_URL_TEST="postgresql://localhost:5432/$DATABASE_NAME_TEST" # Differentiate test db from dev db. Test DB is wiped on each test run. + +# Rails +export RAILS_ENV="development" # Set to 'production' when deploying for security and performance. + +# Node +export NODE_ENV="development" # Set to 'production' when deploying for security and performance. + ################################################ ######### Optional 3rd Party Services ########## ################################################ diff --git a/.travis.yml b/.travis.yml index 03ab32d14..3b6ad3b50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,10 @@ services: env: global: - RAILS_ENV=test - - DATABASE_URL=postgres://postgres@localhost/ + - DATABASE_URL=postgres://postgres@localhost/Forem_prod_test + - DATABASE_NAME=Forem_prod_test + - DATABASE_URL_TEST=postgres://postgres@localhost/Forem_test + - DATABASE_NAME_TEST=Forem_test # Dummy values needed to verify the app boots via "rails runner" - APP_PROTOCOL=http:// - APP_DOMAIN=localhost:3000 diff --git a/config/database.yml b/config/database.yml index b41e772f6..eb2b8ab26 100644 --- a/config/database.yml +++ b/config/database.yml @@ -19,18 +19,18 @@ default: &default encoding: unicode # For details on connection pooling, see Rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + pool: <%= ENV.fetch("DATABASE_POOL_SIZE") { ENV.fetch("RAILS_MAX_THREADS", 5).to_i } %> connect_timeout: 2 checkout_timeout: 2 variables: - statement_timeout: <%= ENV.fetch('STATEMENT_TIMEOUT', 2500).to_i %> + statement_timeout: <%= ENV.fetch("STATEMENT_TIMEOUT", 2500).to_i %> development: <<: *default - url: <%= ENV.fetch('DATABASE_URL', '') %> - database: PracticalDeveloper_development + url: <%= ENV.fetch("DATABASE_URL", "postgres:///Forem_development") %> + database: <%= ENV.fetch("DATABASE_NAME", "Forem_development") %> variables: - statement_timeout: <%= ENV.fetch('STATEMENT_TIMEOUT', 10_000).to_i %> + statement_timeout: <%= ENV.fetch("STATEMENT_TIMEOUT", 10_000).to_i %> # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. @@ -64,10 +64,10 @@ development: # Do not set this db to the same as development or production. test: <<: *default - url: <%= ENV['DATABASE_URL_TEST'] || ENV['DATABASE_URL'] || ''%> - database: PracticalDeveloper_test<%= ENV['TEST_ENV_NUMBER'] %> + url: <%= ENV.fetch("DATABASE_URL_TEST", "postgres:///Forem_test") %> + database: <%= ENV.fetch("DATABASE_NAME_TEST", "Forem_test") %><%= ENV["TEST_ENV_NUMBER"] %> variables: - statement_timeout: <%= ENV.fetch('STATEMENT_TIMEOUT', 10_000).to_i %> + statement_timeout: <%= ENV.fetch("STATEMENT_TIMEOUT", 10_000).to_i %> # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is @@ -86,11 +86,9 @@ test: # You can use this database configuration with: # # production: -# url: <%= ENV['DATABASE_URL'] %> +# url: <%= ENV["DATABASE_URL"] %> # production: <<: *default - database: PracticalDeveloper_production - pool: <%= ENV['DATABASE_POOL_SIZE'] %> - username: PracticalDeveloper - password: <%= ENV['PRACTICALDEVELOPER_DATABASE_PASSWORD'] %> + url: <%= ENV["DATABASE_URL"] %> + database: <%= ENV["DATABASE_NAME"] %>