nex_basse/backend/docs/migrations/007_add_prompt_template.sql

33 lines
1.9 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 提示词模板表
CREATE TABLE `biz_prompt_template` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(100) NOT NULL COMMENT '模板名称',
`category` VARCHAR(50) NOT NULL COMMENT '分类',
`content` TEXT NOT NULL COMMENT '提示词内容',
`description` VARCHAR(255) COMMENT '描述',
`user_id` INT COMMENT '创建者ID (系统级为NULL)',
`is_system` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否系统内置',
`status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '全局状态1启用 / 0禁用',
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '默认排序',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX `idx_prompt_user_id` (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `sys_user` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 用户提示词配置表
CREATE TABLE `biz_user_prompt_config` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`user_id` INT NOT NULL COMMENT '用户ID',
`template_id` INT NOT NULL COMMENT '模板ID',
`is_active` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '用户是否启用',
`user_sort_order` INT NOT NULL DEFAULT 0 COMMENT '用户自定义排序',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
UNIQUE KEY `uk_user_template` (`user_id`, `template_id`),
INDEX `idx_config_user_id` (`user_id`),
INDEX `idx_config_template_id` (`template_id`),
FOREIGN KEY (`user_id`) REFERENCES `sys_user` (`user_id`) ON DELETE CASCADE,
FOREIGN KEY (`template_id`) REFERENCES `biz_prompt_template` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;