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:
parent
139061e702
commit
61715b43d2
1 changed files with 11 additions and 3 deletions
|
|
@ -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 ──────────────────────────────────────────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue