litellm/db_scripts
Etienne Chabert 4c18f557b1 fix(db_scripts): carry the new spend index through the partition runbooks
partition_spend_logs.sql and unpartition_spend_logs.sql hardcode every
index Prisma defines on LiteLLM_SpendLogs, because `LIKE ... INCLUDING
DEFAULTS INCLUDING GENERATED` copies columns but not indexes. They also
rename the old table's indexes aside first, since index names are unique
per schema and a surviving name makes `CREATE INDEX IF NOT EXISTS` a
silent no-op.

The new (api_key, startTime) index was in neither list, so an operator who
partitions (or unpartitions) after this migration lands gets a replacement
table without it, and Prisma will not recreate it: the migration is already
recorded as applied, and `migrate deploy` skips its drift sanity check when
there is nothing pending.

Verified on Postgres 18 against the shipped migration statements:

  * unpatched partition script -> parent table has no api_key index, and
    re-running the migration's own `CREATE INDEX IF NOT EXISTS` reports
    success while being skipped, because the legacy table still owns the
    name. The recovery an operator would reach for silently does nothing.
  * patched -> index survives partitioning, propagates to every partition
    (LiteLLM_SpendLogs_p*_api_key_startTime_idx) and to DEFAULT, is chosen
    by the planner for the key+date-range query shape the endpoints use,
    and survives the unpartition round-trip with all rows intact.
2026-09-01 16:50:15 +02:00
..
backfill_daily_tool_spend.sql fix(db_scripts): pin the tool spend backfill session to UTC 2026-07-27 12:29:19 -07:00
create_views.py chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
migrate_keys.py fix(migrate_keys.py): add script for migrating keys to new db 2025-07-16 10:18:36 -07:00
partition_spend_logs.sql fix(db_scripts): carry the new spend index through the partition runbooks 2026-09-01 16:50:15 +02:00
unpartition_spend_logs.sql fix(db_scripts): carry the new spend index through the partition runbooks 2026-09-01 16:50:15 +02:00
update_unassigned_teams.py (DB fix) don't run apply_db_fixes on startup (#6604) 2024-11-05 13:43:08 -08:00