Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:BerriAI Litellm Prisma Migration

From Leeroopedia
Knowledge Sources Domains Last Updated
BerriAI/litellm repository Database Migrations, Prisma ORM, Schema Management 2026-02-15

Overview

Concrete tool for applying initial Prisma database migrations on Docker setup provided by the LiteLLM prisma_migration.py script.

Description

The prisma_migration.py script is a standalone entry point designed for Docker-based deployments. It performs two critical operations in sequence: first, it runs the LiteLLM proxy CLI with the --skip_server_startup flag to initialize configuration and environment without starting the HTTP server; second, it executes prisma generate as a subprocess to generate the Prisma client from the schema definition. This script is typically invoked as part of a Docker container entrypoint or initialization step before the main proxy server starts.

The script:

  • Adds the current directory to sys.path for import resolution.
  • Invokes run_server(["--skip_server_startup"], standalone_mode=False) via the Click CLI framework.
  • Runs prisma generate as a subprocess, capturing stdout and stderr.
  • Logs the results and reports any failures.

The actual database schema migrations (via prisma migrate deploy) are typically handled separately by the proxy startup logic or container orchestration.

Usage

Use this script when:

  • Setting up a new LiteLLM proxy deployment with Docker.
  • Running database initialization as a separate step from server startup.
  • Generating the Prisma client after schema changes in a CI/CD pipeline.

Code Reference

Attribute Value
Source Location litellm/proxy/prisma_migration.py, lines 1-28
Entry Point Script executed directly: python prisma_migration.py
External Tool prisma generate -- Prisma CLI subprocess invocation
Import from litellm.proxy.proxy_cli import run_server

I/O Contract

Inputs

Input Type Description
DATABASE_URL Environment variable (str) PostgreSQL or SQLite connection string used by Prisma to connect to the database.
Prisma schema file File (schema.prisma) The Prisma schema definition located at litellm/proxy/schema.prisma, defining the database tables and relationships.
WORKER_CONFIG or CONFIG_FILE_PATH Environment variable (str) Optional path to the proxy YAML configuration file, resolved during the run_server initialization phase.

Outputs

Output Type Description
Generated Prisma client File artifacts Python client code generated in the Prisma client output directory, providing type-safe database access.
Exit code int 0 on success; non-zero if prisma generate fails.
Log output stdout/stderr Captured output from the prisma generate command, logged via verbose_proxy_logger.

Usage Examples

Running the migration script in a Docker entrypoint:

# In Dockerfile or docker-compose entrypoint
python litellm/proxy/prisma_migration.py

Script internals (from source):

import os
import subprocess
import sys

sys.path.insert(0, os.path.abspath("./"))

from litellm._logging import verbose_proxy_logger
from litellm.proxy.proxy_cli import run_server

# Initialize config without starting the server
run_server(["--skip_server_startup"], standalone_mode=False)

# Generate Prisma client from schema
verbose_proxy_logger.info("Running 'prisma generate'...")
result = subprocess.run(["prisma", "generate"], capture_output=True, text=True)
verbose_proxy_logger.info(f"'prisma generate' stdout: {result.stdout}")
exit_code = result.returncode

if exit_code != 0:
    verbose_proxy_logger.info(f"'prisma generate' failed with exit code {exit_code}.")
    verbose_proxy_logger.error(f"'prisma generate' stderr: {result.stderr}")

Using Prisma migrate deploy in production:

# Apply pending migrations to the database
prisma migrate deploy --schema=litellm/proxy/schema.prisma

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment