Skip to content

Commit 9fe91af

Browse files
fix: ensure DATABASE_URL is set in .env for Prisma during updates
- Add ensure_database_url() function to update.sh - Function checks if .env exists and creates from .env.example if needed - Automatically adds DATABASE_URL if not present - Call function after restore_backup_files() in update flow - Fixes Prisma client generation error during updates
1 parent 14a3d99 commit 9fe91af

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

update.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,36 @@ restore_backup_files() {
412412
fi
413413
}
414414

415+
# Ensure DATABASE_URL is set in .env file for Prisma
416+
ensure_database_url() {
417+
log "Ensuring DATABASE_URL is set in .env file..."
418+
419+
# Check if .env file exists
420+
if [ ! -f ".env" ]; then
421+
log_warning ".env file not found, creating from .env.example..."
422+
if [ -f ".env.example" ]; then
423+
cp ".env.example" ".env"
424+
else
425+
log_error ".env.example not found, cannot create .env file"
426+
return 1
427+
fi
428+
fi
429+
430+
# Check if DATABASE_URL is already set
431+
if grep -q "^DATABASE_URL=" .env; then
432+
log "DATABASE_URL already exists in .env file"
433+
return 0
434+
fi
435+
436+
# Add DATABASE_URL to .env file
437+
log "Adding DATABASE_URL to .env file..."
438+
echo "" >> .env
439+
echo "# Database" >> .env
440+
echo "DATABASE_URL=\"file:./data/database.sqlite\"" >> .env
441+
442+
log_success "DATABASE_URL added to .env file"
443+
}
444+
415445
# Check if systemd service exists
416446
check_service() {
417447
# systemctl status returns 0-3 if service exists (running, exited, failed, etc.)
@@ -864,6 +894,9 @@ main() {
864894
# Restore .env and data directory before building
865895
restore_backup_files
866896

897+
# Ensure DATABASE_URL is set for Prisma
898+
ensure_database_url
899+
867900
# Install dependencies and build
868901
if ! install_and_build; then
869902
log_error "Install and build failed, rolling back..."

0 commit comments

Comments
 (0)