From 61715b43d2b59d2f47e533f76786e82d2cb0e5e9 Mon Sep 17 00:00:00 2001 From: Chris Parsons <438676+chrisparsons83@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:38:09 -0700 Subject: [PATCH] Load PROD_DATABASE_URL from .env automatically (#259) Mirrors how DATABASE_URL is loaded, so users can store both in their local .env instead of passing PROD_DATABASE_URL inline each time. https://claude.ai/code/session_01EiYh5ZiuWAnpo1PND45Yi1 Co-authored-by: Claude --- scripts/sync-prod-db.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/sync-prod-db.sh b/scripts/sync-prod-db.sh index 7af1ddf..3cf79d9 100755 --- a/scripts/sync-prod-db.sh +++ b/scripts/sync-prod-db.sh @@ -5,9 +5,12 @@ # then sanitizes the copy to prevent outbound notifications and reduce PII exposure. # # Usage: -# PROD_DATABASE_URL="postgres://..." npm run db:sync-prod +# Add PROD_DATABASE_URL to your .env file, then: +# npm run db:sync-prod +# # or pass inline: +# PROD_DATABASE_URL="postgres://..." npm run db:sync-prod # # or pass as argument: -# bash scripts/sync-prod-db.sh "postgres://..." +# bash scripts/sync-prod-db.sh "postgres://..." # # Requirements: pg_dump, pg_restore, psql (PostgreSQL client tools) @@ -35,11 +38,16 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ENV_FILE="$SCRIPT_DIR/../.env" if [[ -f "$ENV_FILE" ]]; then - # Export only DATABASE_URL from .env (avoid polluting env with unrelated vars) + # Export DATABASE_URL and PROD_DATABASE_URL from .env if not already set in the environment DATABASE_URL_FROM_ENV=$(grep -E '^DATABASE_URL=' "$ENV_FILE" | head -1 | cut -d= -f2- | sed 's/^"//' | sed 's/"$//') if [[ -n "$DATABASE_URL_FROM_ENV" && -z "${DATABASE_URL:-}" ]]; then export DATABASE_URL="$DATABASE_URL_FROM_ENV" fi + + PROD_DATABASE_URL_FROM_ENV=$(grep -E '^PROD_DATABASE_URL=' "$ENV_FILE" | head -1 | cut -d= -f2- | sed 's/^"//' | sed 's/"$//') + if [[ -n "$PROD_DATABASE_URL_FROM_ENV" && -z "${PROD_DATABASE_URL:-}" ]]; then + export PROD_DATABASE_URL="$PROD_DATABASE_URL_FROM_ENV" + fi fi # ── Resolve URLs ──────────────────────────────────────────────────────────────