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 <noreply@anthropic.com>
This commit is contained in:
Chris Parsons 2026-04-03 15:38:09 -07:00 committed by GitHub
parent 139061e702
commit 61715b43d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,9 +5,12 @@
# then sanitizes the copy to prevent outbound notifications and reduce PII exposure. # then sanitizes the copy to prevent outbound notifications and reduce PII exposure.
# #
# Usage: # 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: # # 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) # 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" ENV_FILE="$SCRIPT_DIR/../.env"
if [[ -f "$ENV_FILE" ]]; then 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/"$//') 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 if [[ -n "$DATABASE_URL_FROM_ENV" && -z "${DATABASE_URL:-}" ]]; then
export DATABASE_URL="$DATABASE_URL_FROM_ENV" export DATABASE_URL="$DATABASE_URL_FROM_ENV"
fi 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 fi
# ── Resolve URLs ────────────────────────────────────────────────────────────── # ── Resolve URLs ──────────────────────────────────────────────────────────────