import os import subprocess import sys # Connection string for Neon DB (from previous step) DB_URL = "postgresql://neondb_owner:npg_3tJWPqo9kRsf@ep-fancy-field-aedyuut2-pooler.c-2.us-east-2.aws.neon.tech/neondb?channel_binding=require&sslmode=require" def run_migration(): print("🚀 Starting Prisma Migration to Neon DB...") # Set environment variable for this process env = os.environ.copy() env["DATABASE_URL"] = DB_URL # Command to run migration # Assuming we are in root, schema is in apps/backend/prisma/schema.prisma cmd = ["npx", "prisma", "migrate", "deploy", "--schema", "apps/backend/prisma/schema.prisma"] print(f"Running: {' '.join(cmd)}") try: result = subprocess.run( cmd, env=env, shell=True, # shell=True often needed on Windows for npx check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) print("✅ Migration Successful!") print(result.stdout) except subprocess.CalledProcessError as e: print("❌ Migration Failed:") print(e.stderr) print(e.stdout) sys.exit(1) if __name__ == "__main__": run_migration()