Local chat history persistence. Same model used by both home and contextual channels. Indexes on (session_id, created_at) and (channel, updated_at) for ordering and listing.
24 lines
738 B
SQL
24 lines
738 B
SQL
CREATE TABLE `ai_chat_messages` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`session_id` text NOT NULL,
|
|
`role` text NOT NULL,
|
|
`content` text NOT NULL,
|
|
`tool_calls` text,
|
|
`tool_results` text,
|
|
`scope` text,
|
|
`created_at` integer NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `ai_chat_sessions` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`channel` text NOT NULL,
|
|
`title` text,
|
|
`created_at` integer NOT NULL,
|
|
`updated_at` integer NOT NULL,
|
|
`last_scope` text
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX IF NOT EXISTS `ai_chat_messages_session_created_idx` ON `ai_chat_messages` (`session_id`, `created_at`);
|
|
--> statement-breakpoint
|
|
CREATE INDEX IF NOT EXISTS `ai_chat_sessions_channel_updated_idx` ON `ai_chat_sessions` (`channel`, `updated_at`);
|