mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-22 10:40:46 +00:00
refactor(proxy): build the legacy fallback result without rebinding
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
2ab2718c21
commit
4f69f0dacc
1 changed files with 31 additions and 28 deletions
|
|
@ -489,34 +489,11 @@ class ProxyExtrasDBManager:
|
|||
# Fall back: run each migration SQL file directly via prisma db execute.
|
||||
# This works with pooler URLs (no schema introspection needed) and is
|
||||
# safe to re-run because migrations use IF NOT EXISTS / IF EXISTS guards.
|
||||
migration_files = sorted(Path(migrations_dir).glob("migrations/*/migration.sql"))
|
||||
fallback_ok = True
|
||||
for mig_file in migration_files:
|
||||
try:
|
||||
prisma_toolchain.run_prisma(
|
||||
[
|
||||
_get_prisma_command(),
|
||||
"db",
|
||||
"execute",
|
||||
"--file",
|
||||
str(mig_file),
|
||||
"--schema",
|
||||
schema_path,
|
||||
],
|
||||
timeout=prisma_command_timeout(),
|
||||
env=_get_prisma_env(),
|
||||
)
|
||||
logger.info(f"Applied migration: {mig_file.parent.name}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.warning(
|
||||
f"Failed to apply migration {mig_file.parent.name}: {e.stderr}"
|
||||
)
|
||||
if not ProxyExtrasDBManager._is_idempotent_error(str(e.stderr or "")): # pyright: ignore[reportAny] # CalledProcessError.stderr is Any
|
||||
fallback_ok = False
|
||||
except subprocess.TimeoutExpired:
|
||||
logger.warning(f"Migration {mig_file.parent.name} timed out.")
|
||||
fallback_ok = False
|
||||
if mark_all_applied and fallback_ok:
|
||||
results: Final = tuple(
|
||||
ProxyExtrasDBManager._execute_migration_file(mig_file, schema_path)
|
||||
for mig_file in sorted(Path(migrations_dir).glob("migrations/*/migration.sql"))
|
||||
)
|
||||
if mark_all_applied and all(results):
|
||||
ProxyExtrasDBManager._mark_migrations_applied(migrations_dir)
|
||||
return
|
||||
logger.info(f"Migration diff created at {diff_sql_path}")
|
||||
|
|
@ -573,6 +550,32 @@ class ProxyExtrasDBManager:
|
|||
return
|
||||
ProxyExtrasDBManager._mark_migrations_applied(migrations_dir)
|
||||
|
||||
@staticmethod
|
||||
def _execute_migration_file(mig_file: Path, schema_path: str) -> bool:
|
||||
try:
|
||||
prisma_toolchain.run_prisma(
|
||||
[
|
||||
_get_prisma_command(),
|
||||
"db",
|
||||
"execute",
|
||||
"--file",
|
||||
str(mig_file),
|
||||
"--schema",
|
||||
schema_path,
|
||||
],
|
||||
timeout=prisma_command_timeout(),
|
||||
env=_get_prisma_env(),
|
||||
)
|
||||
logger.info(f"Applied migration: {mig_file.parent.name}")
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
stderr: Final = str(e.stderr or "") # pyright: ignore[reportAny] # CalledProcessError.stderr is Any
|
||||
logger.warning(f"Failed to apply migration {mig_file.parent.name}: {stderr}")
|
||||
return ProxyExtrasDBManager._is_idempotent_error(stderr)
|
||||
except subprocess.TimeoutExpired:
|
||||
logger.warning(f"Migration {mig_file.parent.name} timed out.")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _mark_migrations_applied(migrations_dir: str) -> None:
|
||||
migration_names = ProxyExtrasDBManager._get_migration_names(migrations_dir)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue