From 559d396f4e772c6f02999ce31db4a8104ab97cc8 Mon Sep 17 00:00:00 2001 From: "Aaron K. Clark" Date: Tue, 19 May 2026 01:37:32 -0500 Subject: [PATCH] =?UTF-8?q?fix(compose):=20use=20DB=5FUSER=20consistently?= =?UTF-8?q?=20=E2=80=94=20DB=5FUSERNAME=20silently=20dropped=20operator=20?= =?UTF-8?q?overrides?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `app/config/env.js` reads `process.env.DB_USER` (and `.env.example` documents it). But `docker-compose.yml` and two README sections referenced `DB_USERNAME`. The mismatch was silent and harmless on defaults — both compose interpolation and the container's app fell back to `"timetracker"` — but it meant an operator who set `DB_USER=foo` in their `.env` got that value SILENTLY DROPPED by docker-compose's `${DB_USERNAME:-timetracker}` interpolation, and both Postgres and the app ended up on the default user instead. The connection still worked (matching by coincidence), but the operator's stated config never reached the container. Replace every `DB_USERNAME` reference with `DB_USER`: - docker-compose.yml (5 occurrences): POSTGRES_USER, the pg_isready healthcheck, PGUSER for the setup service, and the env passthroughs on the migrate + api services. - tests/integration/README.md (1 occurrence): the env-var export example in the manual integration-test recipe. - README.md (1 occurrence): the same env-var export in the quickstart for running integration tests. Backward-compat note: anyone with an existing `.env` that set the undocumented `DB_USERNAME` variable will need to rename it to `DB_USER`. The CI workflow already uses `DB_USER` and continues to work unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) --- README.md | 2 +- docker-compose.yml | 10 +++++----- tests/integration/README.md | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 565d056..f7a2014 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ Short version: cp .env.example .env # set DB_PASSWORD sudo docker compose up -d postgres setup migrate DB_HOST=localhost DB_PORT=5432 DB_NAME=timetracker \ - DB_USERNAME=timetracker DB_PASSWORD=$(grep ^DB_PASSWORD= .env | cut -d= -f2-) \ + DB_USER=timetracker DB_PASSWORD=$(grep ^DB_PASSWORD= .env | cut -d= -f2-) \ npx vitest run tests/integration sudo docker compose down -v # cleanup ``` diff --git a/docker-compose.yml b/docker-compose.yml index 5954304..4e5944a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,13 +18,13 @@ services: image: postgres:16-alpine restart: unless-stopped environment: - POSTGRES_USER: ${DB_USERNAME:-timetracker} + POSTGRES_USER: ${DB_USER:-timetracker} POSTGRES_PASSWORD: ${DB_PASSWORD:?DB_PASSWORD must be set in .env} POSTGRES_DB: ${DB_NAME:-timetracker} volumes: - postgres-data:/var/lib/postgresql/data healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-timetracker} -d ${DB_NAME:-timetracker}"] + test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-timetracker} -d ${DB_NAME:-timetracker}"] interval: 5s timeout: 3s retries: 10 @@ -43,7 +43,7 @@ services: condition: service_healthy environment: PGHOST: postgres - PGUSER: ${DB_USERNAME:-timetracker} + PGUSER: ${DB_USER:-timetracker} PGPASSWORD: ${DB_PASSWORD} PGDATABASE: ${DB_NAME:-timetracker} volumes: @@ -73,7 +73,7 @@ services: DB_HOST: postgres DB_PORT: 5432 DB_NAME: ${DB_NAME:-timetracker} - DB_USERNAME: ${DB_USERNAME:-timetracker} + DB_USER: ${DB_USER:-timetracker} DB_PASSWORD: ${DB_PASSWORD} NODE_ENV: production # npx + the locally-installed sequelize-cli — no global install @@ -96,7 +96,7 @@ services: DB_HOST: postgres DB_PORT: 5432 DB_NAME: ${DB_NAME:-timetracker} - DB_USERNAME: ${DB_USERNAME:-timetracker} + DB_USER: ${DB_USER:-timetracker} DB_PASSWORD: ${DB_PASSWORD} PORT: 3000 HOST: 0.0.0.0 diff --git a/tests/integration/README.md b/tests/integration/README.md index 518b4c3..6daa1bc 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -23,7 +23,7 @@ sudo docker compose up -d postgres setup migrate sudo docker compose ps -a # postgres: healthy, setup/migrate: Exited (0) # 3. Run the integration suite with DB vars set. -export DB_HOST=localhost DB_PORT=5432 DB_NAME=timetracker DB_USERNAME=timetracker +export DB_HOST=localhost DB_PORT=5432 DB_NAME=timetracker DB_USER=timetracker export DB_PASSWORD=$(grep '^DB_PASSWORD=' .env | cut -d= -f2-) npx vitest run tests/integration