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(db): partition runbook moves the call-id index off the legacy spend logs table (#46131)

devin-ai-integration[bot]9f511e1b2510
diff --git a/db_scripts/partition_spend_logs.sql b/db_scripts/partition_spend_logs.sql
index c153a67eaec..750c1a934aa 100644
--- a/db_scripts/partition_spend_logs.sql
+++ b/db_scripts/partition_spend_logs.sql
@@ -55,6 +55,8 @@ ALTER INDEX IF EXISTS "LiteLLM_SpendLogs_session_id_idx"
RENAME TO "LiteLLM_SpendLogs_legacy_session_id_idx";
ALTER INDEX IF EXISTS "LiteLLM_SpendLogs_api_key_startTime_idx"
RENAME TO "LiteLLM_SpendLogs_legacy_api_key_startTime_idx";
+ALTER INDEX IF EXISTS "LiteLLM_SpendLogs_litellm_call_id_idx"
+ RENAME TO "LiteLLM_SpendLogs_legacy_litellm_call_id_idx";
CREATE TABLE "LiteLLM_SpendLogs" (
LIKE "LiteLLM_SpendLogs_legacy" INCLUDING DEFAULTS INCLUDING GENERATED
diff --git a/tests/integration/database/migrations/test_request_log_indexes.py b/tests/integration/database/migrations/test_request_log_indexes.py
index 754cffce6a1..3b6d1eaf21a 100644
--- a/tests/integration/database/migrations/test_request_log_indexes.py
+++ b/tests/integration/database/migrations/test_request_log_indexes.py
@@ -531,6 +531,21 @@ def test_an_invalid_child_index_left_by_an_interrupted_build_is_rebuilt_and_atta
_assert_index_covers_every_partition(partitioned_database, CALL_ID_INDEX, "litellm_call_id_idx")
+@requires_db
+def test_partitioning_a_table_the_index_job_already_covered_moves_its_call_id_index_aside(scratch_database: str) -> None:
+ """The runbook renames the Prisma indexes off the legacy table so the partitioned table can take their
+ names. The call-id index is built by the index job, not Prisma, and a deployment that partitions after
+ that job ran kept the name on the legacy table, so every later job run reported it as on another table."""
+ assert ensure_request_log_indexes(scratch_database, "public") is True
+ assert _indexed_table(scratch_database, CALL_ID_INDEX) == "LiteLLM_SpendLogs"
+
+ _partition_spend_logs(scratch_database)
+
+ assert _indexed_table(scratch_database, "LiteLLM_SpendLogs_legacy_litellm_call_id_idx") == "LiteLLM_SpendLogs_legacy"
+ assert ensure_request_log_indexes(scratch_database, "public") is True
+ _assert_index_covers_every_partition(scratch_database, CALL_ID_INDEX, "litellm_call_id_idx")
+
+
@requires_db
def test_an_index_of_that_name_on_another_table_is_left_alone_and_reported(partitioned_database: str) -> None:
with psycopg.connect(partitioned_database, autocommit=True) as conn: