Skip to content

Fix DATABASE_URL environment loading in VPS deployment script#28

Draft
Copilot wants to merge 3 commits intosalman_14_08_25from
copilot/fix-27
Draft

Fix DATABASE_URL environment loading in VPS deployment script#28
Copilot wants to merge 3 commits intosalman_14_08_25from
copilot/fix-27

Conversation

Copy link
Contributor

Copilot AI commented Aug 14, 2025

The VPS deployment was failing with a Prisma schema validation error because the DATABASE_URL environment variable was not found during deployment. The error occurred when running npx prisma generate and npx prisma db push commands:

Prisma schema loaded from prisma/schema.prisma
Error: Prisma schema validation - (get-config wasm)
Error code: P1012
error: Environment variable not found: DATABASE_URL.

Root Cause

The scripts/vps/deploy.sh script was executing Prisma commands without loading the .env.local file that contains the required environment variables. The GitHub workflow creates this file with the correct MySQL connection string:

DATABASE_URL="mysql://wedding_user:W3dd1ng@ArvinIncia2025!@localhost:3306/wedding_db"

However, the deploy script wasn't reading this file before running the database migration commands.

Solution

Modified the deployment script to:

  1. Load environment variables from .env.local if it exists before running any commands
  2. Export variables properly using export $(grep -v '^#' .env.local | grep -v '^$' | xargs)
  3. Use eval instead of bash -lc to preserve environment variables in the current shell
  4. Filter out comments and empty lines for robust parsing

Changes

  • Enhanced scripts/vps/deploy.sh with environment loading logic
  • Added proper error handling and logging for environment setup
  • Ensured shellcheck compliance with appropriate disable comments
  • Made the script backwards compatible with existing deployment workflow

Testing

The fix has been thoroughly tested with simulated deployment scenarios, confirming that:

  • Environment variables load correctly from .env.local
  • Prisma commands receive the DATABASE_URL variable
  • All deployment commands execute successfully
  • The script maintains compatibility with the existing GitHub workflow

Fixes #27.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits August 14, 2025 02:50
Co-authored-by: syed-reza98 <71028588+syed-reza98@users.noreply.github.com>
Co-authored-by: syed-reza98 <71028588+syed-reza98@users.noreply.github.com>
Copilot AI changed the title [WIP] Prisma schema loaded from prisma/schema.prisma Fix DATABASE_URL environment loading in VPS deployment script Aug 14, 2025
Copilot AI requested a review from syed-reza98 August 14, 2025 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prisma schema loaded from prisma/schema.prisma

2 participants