From d4751053f30ce2a845690f31abb1889c08e8ffa1 Mon Sep 17 00:00:00 2001 From: Rob Zolkos Date: Mon, 5 Feb 2024 23:17:50 -0500 Subject: [PATCH] Fix database config for non-devcontainer environments (#318) Back in this [commit](https://github.com/maybe-finance/maybe/commit/5f50ea3f02bfc1797816e3c679065c611fc61347#diff-5a674c769541a71f2471a45c0e9dde911b4455344e3131bddc5a363701ba6325R22-R23) I added a default postgres user and password. Often this is not the user and password that is used in non-devcontainer environments. This commit uses environment variables that are set in the devcontainer to set the user and password in the database.yml file. If the environment variables are not set, it falls back to the default user and password on the users system. --- .devcontainer/docker-compose.yml | 2 ++ config/database.yml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index bae4f3b8..1e21892b 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -18,6 +18,8 @@ services: environment: DB_HOST: db HOST: "0.0.0.0" + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres depends_on: - db diff --git a/config/database.yml b/config/database.yml index 79cef70b..c718f1f7 100644 --- a/config/database.yml +++ b/config/database.yml @@ -19,8 +19,8 @@ default: &default # https://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> host: <%= ENV.fetch("DB_HOST") { "127.0.0.1" } %> - password: postgres - user: postgres + password: <%= ENV.fetch("POSTGRES_PASSWORD") { nil } %> + user: <%= ENV.fetch("POSTGRES_USER") { nil } %> development: <<: *default