You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
364 lines
16 KiB
364 lines
16 KiB
CREATE TABLE `agent_tool_logs` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`tool_id` text NOT NULL,
|
|
`tool_slug` text(50) NOT NULL,
|
|
`user_id` integer,
|
|
`input` text NOT NULL,
|
|
`output` text,
|
|
`status` text(20) NOT NULL,
|
|
`error_message` text,
|
|
`duration_ms` integer NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `agent_tool_logs_tool_id_idx` ON `agent_tool_logs` (`tool_id`);--> statement-breakpoint
|
|
CREATE INDEX `agent_tool_logs_created_at_idx` ON `agent_tool_logs` (`created_at`);--> statement-breakpoint
|
|
CREATE TABLE `agent_tools` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`name` text(50) NOT NULL,
|
|
`slug` text(50) NOT NULL,
|
|
`description` text NOT NULL,
|
|
`type` text(30) NOT NULL,
|
|
`config` text NOT NULL,
|
|
`enabled` integer DEFAULT 1 NOT NULL,
|
|
`needs_approval` integer DEFAULT 0 NOT NULL,
|
|
`admin_only` integer DEFAULT 0 NOT NULL,
|
|
`sort_order` integer DEFAULT 0 NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `agent_tools_slug_idx` ON `agent_tools` (`slug`);--> statement-breakpoint
|
|
CREATE INDEX `agent_tools_enabled_idx` ON `agent_tools` (`enabled`);--> statement-breakpoint
|
|
CREATE TABLE `agent_message_feedback` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`message_id` text NOT NULL,
|
|
`user_id` integer NOT NULL,
|
|
`feedback` text(10) NOT NULL,
|
|
`comment` text,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
FOREIGN KEY (`message_id`) REFERENCES `agent_messages`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `idx_agent_feedback_message_user` ON `agent_message_feedback` (`message_id`,`user_id`);--> statement-breakpoint
|
|
CREATE TABLE `agent_messages` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`session_id` text NOT NULL,
|
|
`role` text(20) NOT NULL,
|
|
`content` text DEFAULT '' NOT NULL,
|
|
`parts` text,
|
|
`model_id` integer,
|
|
`input_tokens` integer,
|
|
`output_tokens` integer,
|
|
`sort_order` integer NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
FOREIGN KEY (`session_id`) REFERENCES `agent_sessions`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_agent_messages_session_sort` ON `agent_messages` (`session_id`,`sort_order`);--> statement-breakpoint
|
|
CREATE TABLE `agent_sessions` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`agent_id` integer,
|
|
`user_id` integer,
|
|
`temp_token` text(64),
|
|
`title` text(100) DEFAULT '新对话' NOT NULL,
|
|
`model_id` integer,
|
|
`enable_thinking` integer,
|
|
`enable_tools` integer,
|
|
`last_active_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`expires_at` integer,
|
|
`deleted_at` integer,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
FOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE set null,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_agent_sessions_user_deleted` ON `agent_sessions` (`user_id`,`deleted_at`);--> statement-breakpoint
|
|
CREATE INDEX `idx_agent_sessions_temp_token` ON `agent_sessions` (`temp_token`);--> statement-breakpoint
|
|
CREATE INDEX `idx_agent_sessions_agent` ON `agent_sessions` (`agent_id`);--> statement-breakpoint
|
|
CREATE TABLE `agent_tool_associations` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`agent_id` integer NOT NULL,
|
|
`tool_id` text NOT NULL,
|
|
`needs_approval` integer,
|
|
`sort_order` integer DEFAULT 0 NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
FOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
FOREIGN KEY (`tool_id`) REFERENCES `agent_tools`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `agent_tool_assoc_uniq` ON `agent_tool_associations` (`agent_id`,`tool_id`);--> statement-breakpoint
|
|
CREATE TABLE `agents` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`slug` text(50) NOT NULL,
|
|
`name` text(100) NOT NULL,
|
|
`description` text,
|
|
`system_prompt` text DEFAULT '' NOT NULL,
|
|
`default_model_id` integer,
|
|
`title_model_id` integer,
|
|
`title_strategy` text(20) DEFAULT 'llm' NOT NULL,
|
|
`enable_thinking` integer DEFAULT 0 NOT NULL,
|
|
`enable_tools` integer DEFAULT 1 NOT NULL,
|
|
`max_step_count` integer DEFAULT 6 NOT NULL,
|
|
`is_default` integer DEFAULT 0 NOT NULL,
|
|
`is_callable` integer DEFAULT 0 NOT NULL,
|
|
`sort_order` integer DEFAULT 0 NOT NULL,
|
|
`enabled` integer DEFAULT 1 NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `agents_slug_unique` ON `agents` (`slug`);--> statement-breakpoint
|
|
CREATE INDEX `agents_enabled_idx` ON `agents` (`enabled`);--> statement-breakpoint
|
|
CREATE INDEX `agents_sort_order_idx` ON `agents` (`sort_order`);--> statement-breakpoint
|
|
CREATE TABLE `oauth_accounts` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`user_id` integer NOT NULL,
|
|
`provider` text NOT NULL,
|
|
`provider_user_id` text NOT NULL,
|
|
`username` text,
|
|
`email` text,
|
|
`avatar` text,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)),
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `sessions` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`user_id` integer NOT NULL,
|
|
`expires_at` integer NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `sessions_user_id_idx` ON `sessions` (`user_id`);--> statement-breakpoint
|
|
CREATE TABLE `users` (
|
|
`id` integer PRIMARY KEY NOT NULL,
|
|
`username` text NOT NULL,
|
|
`email` text,
|
|
`nickname` text,
|
|
`password` text NOT NULL,
|
|
`avatar` text,
|
|
`role` text DEFAULT 'user' NOT NULL,
|
|
`status` text DEFAULT 'active' NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `users_username_unique` ON `users` (`username`);--> statement-breakpoint
|
|
CREATE TABLE `app_configs` (
|
|
`key` text PRIMARY KEY NOT NULL,
|
|
`value` text NOT NULL,
|
|
`value_type` text NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `user_configs` (
|
|
`user_id` integer NOT NULL,
|
|
`key` text NOT NULL,
|
|
`value` text NOT NULL,
|
|
`value_type` text NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
PRIMARY KEY(`user_id`, `key`),
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `user_configs_user_id_idx` ON `user_configs` (`user_id`);--> statement-breakpoint
|
|
CREATE TABLE `article_cards` (
|
|
`article_id` integer NOT NULL,
|
|
`card_id` integer NOT NULL,
|
|
`sort_order` integer DEFAULT 0 NOT NULL,
|
|
PRIMARY KEY(`article_id`, `card_id`),
|
|
FOREIGN KEY (`article_id`) REFERENCES `articles`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
FOREIGN KEY (`card_id`) REFERENCES `cards`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_article_card_article` ON `article_cards` (`article_id`);--> statement-breakpoint
|
|
CREATE INDEX `idx_article_card_card` ON `article_cards` (`card_id`);--> statement-breakpoint
|
|
CREATE TABLE `articles` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`title` text(255) NOT NULL,
|
|
`content` text NOT NULL,
|
|
`summary` text,
|
|
`cover` text(500),
|
|
`status` text DEFAULT 'draft' NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_article_status` ON `articles` (`status`);--> statement-breakpoint
|
|
CREATE INDEX `idx_article_created` ON `articles` (`created_at`);--> statement-breakpoint
|
|
CREATE TABLE `card_images` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`card_id` integer NOT NULL,
|
|
`url` text(500) NOT NULL,
|
|
`sort_order` integer DEFAULT 0 NOT NULL,
|
|
FOREIGN KEY (`card_id`) REFERENCES `cards`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_card_image_card` ON `card_images` (`card_id`);--> statement-breakpoint
|
|
CREATE TABLE `card_tags` (
|
|
`card_id` integer NOT NULL,
|
|
`tag_id` integer NOT NULL,
|
|
PRIMARY KEY(`card_id`, `tag_id`),
|
|
FOREIGN KEY (`card_id`) REFERENCES `cards`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_card_tag_card` ON `card_tags` (`card_id`);--> statement-breakpoint
|
|
CREATE INDEX `idx_card_tag_tag` ON `card_tags` (`tag_id`);--> statement-breakpoint
|
|
CREATE TABLE `cards` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`type` text NOT NULL,
|
|
`title` text(255) NOT NULL,
|
|
`description` text,
|
|
`content` text,
|
|
`aspect_ratio` real,
|
|
`category_id` text,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
FOREIGN KEY (`category_id`) REFERENCES `categories`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_card_category` ON `cards` (`category_id`);--> statement-breakpoint
|
|
CREATE INDEX `idx_card_type` ON `cards` (`type`);--> statement-breakpoint
|
|
CREATE INDEX `idx_card_created` ON `cards` (`created_at`);--> statement-breakpoint
|
|
CREATE TABLE `categories` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`name` text(100) NOT NULL,
|
|
`slug` text(100) NOT NULL,
|
|
`image` text(500),
|
|
`parent_id` text,
|
|
`sort_order` integer DEFAULT 0 NOT NULL,
|
|
`count` integer DEFAULT 0 NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `idx_category_slug` ON `categories` (`slug`);--> statement-breakpoint
|
|
CREATE INDEX `idx_category_parent` ON `categories` (`parent_id`);--> statement-breakpoint
|
|
CREATE TABLE `chat_messages` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`nickname` text(20) NOT NULL,
|
|
`content` text NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`client_id` text,
|
|
`user_id` integer
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_chat_msg_created` ON `chat_messages` (`created_at`);--> statement-breakpoint
|
|
CREATE TABLE `favorites` (
|
|
`user_id` integer NOT NULL,
|
|
`card_id` integer NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
PRIMARY KEY(`user_id`, `card_id`),
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
FOREIGN KEY (`card_id`) REFERENCES `cards`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_favorite_user` ON `favorites` (`user_id`);--> statement-breakpoint
|
|
CREATE INDEX `idx_favorite_card` ON `favorites` (`card_id`);--> statement-breakpoint
|
|
CREATE TABLE `ideas` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`author` text(30) NOT NULL,
|
|
`content` text NOT NULL,
|
|
`platform` text(30),
|
|
`color` text(30),
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_idea_created` ON `ideas` (`created_at`);--> statement-breakpoint
|
|
CREATE TABLE `projects` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`name` text(100) NOT NULL,
|
|
`tags` text(500),
|
|
`description` text(1000),
|
|
`path` text(500),
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_project_created` ON `projects` (`created_at`);--> statement-breakpoint
|
|
CREATE TABLE `tags` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`name` text(50) NOT NULL,
|
|
`slug` text(50) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `idx_tag_slug` ON `tags` (`slug`);--> statement-breakpoint
|
|
CREATE TABLE `tools` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`name` text(50) NOT NULL,
|
|
`slug` text(50) NOT NULL,
|
|
`icon` text(100),
|
|
`sort_order` integer DEFAULT 0 NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `llm_models` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`provider_id` integer NOT NULL,
|
|
`name` text(200) NOT NULL,
|
|
`model_id` text(200) NOT NULL,
|
|
`type` text DEFAULT 'text' NOT NULL,
|
|
`enabled` integer DEFAULT 1 NOT NULL,
|
|
`supports_tools` integer DEFAULT 1 NOT NULL,
|
|
`description` text,
|
|
`max_tokens` integer,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
FOREIGN KEY (`provider_id`) REFERENCES `llm_providers`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `idx_llm_model_provider` ON `llm_models` (`provider_id`);--> statement-breakpoint
|
|
CREATE INDEX `idx_llm_model_type` ON `llm_models` (`type`);--> statement-breakpoint
|
|
CREATE TABLE `llm_providers` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`user_id` integer,
|
|
`name` text(100) NOT NULL,
|
|
`slug` text(100) NOT NULL,
|
|
`base_url` text(500),
|
|
`parse_mode` text DEFAULT 'openai' NOT NULL,
|
|
`api_key` text,
|
|
`status` text DEFAULT 'active' NOT NULL,
|
|
`description` text,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `idx_llm_provider_user_slug` ON `llm_providers` (`user_id`,`slug`);--> statement-breakpoint
|
|
CREATE INDEX `idx_llm_provider_user` ON `llm_providers` (`user_id`);--> statement-breakpoint
|
|
CREATE INDEX `idx_llm_provider_status` ON `llm_providers` (`status`);--> statement-breakpoint
|
|
CREATE TABLE `scheduled_tasks` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`name` text NOT NULL,
|
|
`cron_expression` text NOT NULL,
|
|
`type` text NOT NULL,
|
|
`function_name` text,
|
|
`function_payload` text,
|
|
`http_method` text,
|
|
`http_url` text,
|
|
`http_headers` text,
|
|
`http_body` text,
|
|
`catch_up` integer DEFAULT 0 NOT NULL,
|
|
`enabled` integer DEFAULT 1 NOT NULL,
|
|
`max_retries` integer DEFAULT 0 NOT NULL,
|
|
`retry_delay_seconds` integer DEFAULT 60 NOT NULL,
|
|
`timeout_seconds` integer DEFAULT 300 NOT NULL,
|
|
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `task_execution_logs` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`task_id` text NOT NULL,
|
|
`status` text NOT NULL,
|
|
`started_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
|
|
`finished_at` integer,
|
|
`error_message` text,
|
|
`result_summary` text,
|
|
FOREIGN KEY (`task_id`) REFERENCES `scheduled_tasks`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
|