From ee94046d863361e9a090aa43ef4eeb1bbedf1829 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 13 Oct 2026 08:17:48 -0700 Subject: [PATCH] fix(db): partition runbook moves the call-id index off the legacy spend logs table (#46131) Backport of #46131 to stable/1.103.x. Cherry-picked from 9f511e1b251039117b0707a6e974093a7489fe82 (main). The test moves to the line's tests/proxy_migration_tests/test_request_log_indexes.py. --- db_scripts/partition_spend_logs.sql | 2 ++ .../test_request_log_indexes.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) 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/proxy_migration_tests/test_request_log_indexes.py b/tests/proxy_migration_tests/test_request_log_indexes.py index 39f9f3f56e4..9b31a501271 100644 --- a/tests/proxy_migration_tests/test_request_log_indexes.py +++ b/tests/proxy_migration_tests/test_request_log_indexes.py @@ -518,6 +518,25 @@ 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: