Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(proxy-extras): use DIRECT_URL for prisma migrate diff, tempfile for diff dir

Ishaan Jaffer33a2cee4afa0
diff --git a/litellm-proxy-extras/litellm_proxy_extras/utils.py b/litellm-proxy-extras/litellm_proxy_extras/utils.py
index 87d74513c00..12f16ee9f11 100644
--- a/litellm-proxy-extras/litellm_proxy_extras/utils.py
+++ b/litellm-proxy-extras/litellm_proxy_extras/utils.py
@@ -4,8 +4,8 @@ import random
import re
import shutil
import subprocess
+import tempfile
import time
-from datetime import datetime
from pathlib import Path
from typing import Optional
@@ -256,21 +256,11 @@ class ProxyExtrasDBManager:
if not database_url:
logger.error("DATABASE_URL not set")
return
+ # Prefer DIRECT_URL for schema introspection — pooler URLs (e.g. neon -pooler)
+ # do not support the extended query protocol required by prisma migrate diff.
+ diff_url = os.getenv("DIRECT_URL") or database_url
- diff_dir = (
- Path(migrations_dir)
- / "migrations"
- / f"{datetime.now().strftime('%Y%m%d%H%M%S')}_baseline_diff"
- )
- try:
- diff_dir.mkdir(parents=True, exist_ok=True)
- except Exception as e:
- if "Permission denied" in str(e):
- logger.warning(
- f"Permission denied - {e}\nunable to baseline db. Set LITELLM_MIGRATION_DIR environment variable to a writable directory to enable migrations."
- )
- return
- raise e
+ diff_dir = Path(tempfile.mkdtemp(prefix="litellm_migration_diff_"))
diff_sql_path = diff_dir / "migration.sql"
# 1. Generate migration SQL for the diff between DB and schema
@@ -283,7 +273,7 @@ class ProxyExtrasDBManager:
"migrate",
"diff",
"--from-url",
- database_url,
+ diff_url,
"--to-schema-datamodel",
schema_path,
"--script",