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 ──────────────────────────────────────────────────────────────