#!/bin/bash set -e SERVICE=$1 if [ -z "$SERVICE" ]; then echo "Usage: $0 [dev|deploy]" echo "Example: $0 auth-service dev" echo "Example: $0 auth-service deploy" exit 1 fi if [ ! -d "services/$SERVICE" ]; then echo "❌ Service $SERVICE not found" exit 1 fi echo "🔄 Running migrations for $SERVICE..." cd "services/$SERVICE" # Load environment variables (hybrid pattern) # 1. Load shared env (JWT secrets, Redis config) if [ -f "../../deployments/local/.env.local" ]; then export $(grep -v '^#' ../../deployments/local/.env.local | xargs) fi # 2. Load service-specific env (DATABASE_URL, PORT, etc.) if [ -f ".env.local" ]; then export $(grep -v '^#' .env.local | xargs) fi # Check if DATABASE_URL is set if [ -z "$DATABASE_URL" ]; then echo "⚠️ DATABASE_URL not set. Please check your .env.local files:" echo " - Shared config: ../../deployments/local/.env.local" echo " - Service config: .env.local" echo " For Neon: postgresql://user:pass@ep-xxx.region.neon.tech/dbname?sslmode=require&pgbouncer=true" exit 1 fi if [ "$2" = "dev" ]; then echo "📝 Running development migration (creates new migration)..." pnpm prisma migrate dev else echo "🚀 Running production migration (applies existing migrations)..." pnpm prisma migrate deploy fi echo "✅ Migrations completed!"