| 1 | CREATE TABLE chat_connections (id text PRIMARY KEY, person text, runner_id text, local_id text, provider text, kind text, label text, state text, reason text, plan text, headroom text, prompt text, revision integer, created_at datetime, updated_at datetime); |
| 2 | CREATE INDEX chat_connection_person ON chat_connections(person); |
| 3 | CREATE TABLE chat_usage (id integer PRIMARY KEY, person text, connection text, provider text, model text, role text, task_id text, step_id text, turn_id text, attempt integer, outcome text, complete numeric, input_tokens integer, cached_input_tokens integer, cache_write_tokens integer, output_tokens integer, reasoning_output_tokens integer, recorded_at datetime); |
| 4 | CREATE INDEX chat_usage_person ON chat_usage(person, recorded_at); |
| 5 | CREATE UNIQUE INDEX chat_usage_key ON chat_usage(turn_id, step_id, attempt, connection, model); |
| 6 | ALTER TABLE chat_messages ADD COLUMN switched text; |
| 7 | ALTER TABLE chat_turns ADD COLUMN connection text; |
| 8 | ALTER TABLE chat_steps ADD COLUMN switched text; |
| 9 | ALTER TABLE chat_tool_calls ADD COLUMN op text; |
| 10 | CREATE INDEX chat_tool_call_turn ON chat_tool_calls(turn_id, op); |
| 11 | |