docs(schema): add the missing lookup, retention and FK indexes #46

Merged
KofTwentyTwo merged 2 commits from feature/schema-indexes into develop 2026-10-14 23:00:28 +00:00
KofTwentyTwo commented 2026-10-14 20:26:17 +00:00 (Migrated from github.com)

What

The reference DDL docs/schema-postgres.sql gets an "Index audit" block with six indexes, all IF NOT EXISTS. UPGRADE.md gets a matching note.

Index Why
assistant_usage_turn (turn_id) ScheduledTurn.cost reads usage by turn on every scheduled run. assistant_usage gains a row per model call and is the fastest-growing table.
assistant_turn_event_create_date AssistantStore.deleteTurnEventsBefore (retention)
assistant_tool_call_create_date AssistantStore.clearToolResultsBefore (retention)
assistant_conversation_modify_date AssistantStore.listConversationsInactiveSince (retention)
assistant_scheduled_run_conversation, assistant_scheduled_run_turn ON DELETE SET NULL foreign keys. Deleting a conversation or turn scans the run table without them.

The other FK columns with no index (model, profile and provider references on config-sized tables) are never filtered or joined in code, so this leaves them out on purpose.

Why

This came out of an index audit of the qbits installed on kof22. The qbit ships no Liquibase changelog; hosts own the DDL, and kof22 applies the same six indexes, by the same names, in its own changeset.

No code change, so no tests are affected.

🤖 Generated with Claude Code

## What The reference DDL `docs/schema-postgres.sql` gets an "Index audit" block with six indexes, all `IF NOT EXISTS`. `UPGRADE.md` gets a matching note. | Index | Why | |---|---| | `assistant_usage_turn` (turn_id) | `ScheduledTurn.cost` reads usage by turn on every scheduled run. `assistant_usage` gains a row per model call and is the fastest-growing table. | | `assistant_turn_event_create_date` | `AssistantStore.deleteTurnEventsBefore` (retention) | | `assistant_tool_call_create_date` | `AssistantStore.clearToolResultsBefore` (retention) | | `assistant_conversation_modify_date` | `AssistantStore.listConversationsInactiveSince` (retention) | | `assistant_scheduled_run_conversation`, `assistant_scheduled_run_turn` | `ON DELETE SET NULL` foreign keys. Deleting a conversation or turn scans the run table without them. | The other FK columns with no index (model, profile and provider references on config-sized tables) are never filtered or joined in code, so this leaves them out on purpose. ## Why This came out of an index audit of the qbits installed on kof22. The qbit ships no Liquibase changelog; hosts own the DDL, and kof22 applies the same six indexes, by the same names, in its own changeset. No code change, so no tests are affected. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.