skip db migration on startup

This commit is contained in:
2026-01-15 17:06:42 +02:00
parent 48870802ca
commit a80b2b8d5e

View File

@@ -41,17 +41,49 @@ if [ "$NODE_ENV" = "production" ]; then
echo "✅ Environment validation passed $(date '+%Y-%m-%d %H:%M:%S')"
fi
# Run database migrations if DATABASE_URL is set
if [ -n "$DATABASE_URL" ]; then
echo "🔄 Running database migrations... $(date '+%Y-%m-%d %H:%M:%S')"
migration_output=$(npx prisma migrate deploy 2>&1)
migration_status=$?
echo "$migration_output"
if [ $migration_status -ne 0 ] && ! echo "$migration_output" | grep -q "All migrations are already applied"; then
echo "❌ ERROR: Prisma migrations failed $(date '+%Y-%m-%d %H:%M:%S')"
exit 1
# Allow skipping health check database validation for debugging
if [ "$SKIP_HEALTH_DB_CHECK" = "1" ]; then
echo "⚠️ Skipping database check in health endpoint (SKIP_HEALTH_DB_CHECK=1) $(date '+%Y-%m-%d %H:%M:%S')"
fi
# Run database migrations if DATABASE_URL is set and not skipped
if [ -n "$DATABASE_URL" ] && [ "$SKIP_MIGRATIONS" != "1" ]; then
echo "🔄 Testing database connectivity... $(date '+%Y-%m-%d %H:%M:%S')"
# Test basic database connectivity
echo "SELECT 1;" > /tmp/test.sql
if npx prisma db execute --file /tmp/test.sql >/dev/null 2>&1; then
echo "✅ Database connection successful $(date '+%Y-%m-%d %H:%M:%S')"
rm -f /tmp/test.sql
else
echo "❌ ERROR: Cannot connect to database $(date '+%Y-%m-%d %H:%M:%S')"
echo "Database URL: $(echo "$DATABASE_URL" | sed 's|//.*@|//***:***@|')" # Hide credentials in logs
echo "⚠️ Continuing without migrations..."
rm -f /tmp/test.sql
fi
echo "✅ Migrations complete $(date '+%Y-%m-%d %H:%M:%S')"
echo "🔄 Running database migrations... $(date '+%Y-%m-%d %H:%M:%S')"
# Run migrations with timeout to prevent hanging
timeout 120 sh -c '
echo "Running: npx prisma migrate deploy"
npx prisma migrate deploy 2>&1
exit_code=$?
echo "Migration command completed with exit code: $exit_code"
exit $exit_code
' || {
migration_status=$?
echo "❌ ERROR: Prisma migrations failed or timed out (status: $migration_status) $(date '+%Y-%m-%d %H:%M:%S')"
if [ $migration_status -eq 124 ]; then
echo "⚠️ Migration command timed out after 120 seconds"
fi
# Continue anyway - don't fail the startup for migration issues in production
echo "⚠️ Continuing startup despite migration issues..."
}
echo "✅ Migrations step complete $(date '+%Y-%m-%d %H:%M:%S')"
elif [ "$SKIP_MIGRATIONS" = "1" ]; then
echo "⏭️ Skipping database migrations (SKIP_MIGRATIONS=1) $(date '+%Y-%m-%d %H:%M:%S')"
fi
# Optional: Run seeding if RUN_SEED=1 (set in env vars)