mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-24 18:24:20 +00:00
* feat(spend_management_endpoints.py): expose new endpoint for querying user's usage at 1m+ spend logs Allows user to view their spend at 1m+ spend logs * build(schema.prisma): add api_requests to dailyuserspend table * build(migration.sql): add migration file for new column to daily user spend table * build(prisma_client.py): add logic for copying over migration folder, if deploy/migrations present in expected location enables easier testing of prisma migration flow * build(ui/): initial commit successfully using the dailyuserspend table on the UI * refactor(internal_user_endpoints.py): refactor `/user/daily/activity` to give breakdowns by provider/model/key * feat: feature parity (cost page) with existing 'usage' page * build(ui/): add activity tab to new_usage.tsx gets to feature parity on 'All Up' page of 'usage.tsx' * fix(proxy/utils.py): count number of api requests in daily user spend table allows us to see activity by model on new usage tab * style(new_usage.tsx): fix y-axis to be in ascending order of date * fix: fix linting errors * fix: fix ruff check errors
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
import subprocess
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
|
|
|
|
def create_baseline():
|
|
"""Create baseline migration in deploy/migrations"""
|
|
try:
|
|
# Get paths
|
|
root_dir = Path(__file__).parent.parent
|
|
deploy_dir = root_dir / "deploy"
|
|
migrations_dir = deploy_dir / "migrations"
|
|
schema_path = root_dir / "schema.prisma"
|
|
|
|
# Create migrations directory
|
|
migrations_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Create migration_lock.toml if it doesn't exist
|
|
lock_file = migrations_dir / "migration_lock.toml"
|
|
if not lock_file.exists():
|
|
lock_file.write_text('provider = "postgresql"\n')
|
|
|
|
# Create timestamp-based migration directory
|
|
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
migration_dir = migrations_dir / f"{timestamp}_baseline"
|
|
migration_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Generate migration SQL
|
|
result = subprocess.run(
|
|
[
|
|
"prisma",
|
|
"migrate",
|
|
"diff",
|
|
"--from-empty",
|
|
"--to-schema-datamodel",
|
|
str(schema_path),
|
|
"--script",
|
|
],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
|
|
# Write the SQL to migration.sql
|
|
migration_file = migration_dir / "migration.sql"
|
|
migration_file.write_text(result.stdout)
|
|
|
|
print(f"Created baseline migration in {migration_dir}")
|
|
return True
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Error running prisma command: {e.stderr}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"Error creating baseline migration: {str(e)}")
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
create_baseline()
|