Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions drizzle/0007_add_model_usage.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Model usage tracking table
-- Records token usage for each Claude API call
CREATE TABLE `model_usage` (
`id` text PRIMARY KEY NOT NULL,
`sub_chat_id` text NOT NULL REFERENCES `sub_chats`(`id`) ON DELETE CASCADE,
`chat_id` text NOT NULL REFERENCES `chats`(`id`) ON DELETE CASCADE,
`project_id` text NOT NULL REFERENCES `projects`(`id`) ON DELETE CASCADE,
`model` text NOT NULL,
`input_tokens` integer NOT NULL DEFAULT 0,
`output_tokens` integer NOT NULL DEFAULT 0,
`total_tokens` integer NOT NULL DEFAULT 0,
`cost_usd` text,
`session_id` text,
`message_uuid` text,
`mode` text,
`duration_ms` integer,
`created_at` integer
);--> statement-breakpoint

-- Indexes for query optimization
CREATE INDEX `model_usage_created_at_idx` ON `model_usage` (`created_at`);--> statement-breakpoint
CREATE INDEX `model_usage_model_idx` ON `model_usage` (`model`);--> statement-breakpoint
CREATE INDEX `model_usage_project_id_idx` ON `model_usage` (`project_id`);--> statement-breakpoint
CREATE INDEX `model_usage_chat_id_idx` ON `model_usage` (`chat_id`);--> statement-breakpoint
CREATE INDEX `model_usage_sub_chat_id_idx` ON `model_usage` (`sub_chat_id`);--> statement-breakpoint
-- Unique index for deduplication by message UUID
CREATE UNIQUE INDEX `model_usage_message_uuid_idx` ON `model_usage` (`message_uuid`);
19 changes: 19 additions & 0 deletions drizzle/0007_watery_winter_soldier.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE TABLE `model_usage` (
`id` text PRIMARY KEY NOT NULL,
`sub_chat_id` text NOT NULL,
`chat_id` text NOT NULL,
`project_id` text NOT NULL,
`model` text NOT NULL,
`input_tokens` integer DEFAULT 0 NOT NULL,
`output_tokens` integer DEFAULT 0 NOT NULL,
`total_tokens` integer DEFAULT 0 NOT NULL,
`cost_usd` text,
`session_id` text,
`message_uuid` text,
`mode` text,
`duration_ms` integer,
`created_at` integer,
FOREIGN KEY (`sub_chat_id`) REFERENCES `sub_chats`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`chat_id`) REFERENCES `chats`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade
);
Loading