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 9f511e1b25 (main).

The test moves to the line's tests/proxy_migration_tests/test_request_log_indexes.py.
This commit is contained in:
devin-ai-integration[bot] 2026-10-13 08:17:48 -07:00 • committed by mateo-berri
parent 6a8685a3ee
commit ee94046d86
2 changed files with 21 additions and 0 deletions

View file

@ -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

View file

@ -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: