主要改动: fix(docker/dify-deploy): 修复脚本核心功能 - heredoc 单引号 bug: 'ENVEOF' 改为 ENVEOF,变量正确展开 - 端口默认值 8083/8084/8085 对齐 .env.prod 生产配置 - 加 dc_cmd() 兼容 docker-compose v1/v2 plugin - openssl rand 生成强随机密码与 SECRET_KEY(42 字符) - install 跳过已存在 .env,保护用户配置(管理员密码/SECRET_KEY) - read -p < /dev/tty 兼容非 tty 环境(CI/CD) - show-config 改用 DIFY_NGINX_PORT(nginx 入口)而非 APP_WEB_PORT docs(mvp-design): 修正 §3.2 workflow inputs 描述 - 实际只有 query,删除错误的 user_id input 声明 - 节点序列图同步更新 feat(aiChatService): 新增 Dify 客户端与适配器 - service/dify_client.go: Dify Workflow 调用 + SSE 解析 - service/dify_adapter.go: 与现有 chat_service 桥接 - provider/ai_chat_provider.go: Dubbo 入口简化 - main.go: 装配 ConversationRepository + DifyClient feat(migrations): 新增 AI 搭子会话表 ai_chat.sql - ai_conversations / ai_messages 表 + 索引 docs: 新增 Dify 集成设计文档 - 2026-06-29-ai-chat-dify-mvp-design.md (MVP 实施级) - 2026-06-29-ai-chat-dify-integration-v2-design.md (V2 演进路线图) - docs/dify/角角.yml (Workflow DSL 导出) config: 更新 env 模板与 docker 配置 - backend/.env.example: DIFY_* 环境变量声明 - docker/.env.prod: DIFY_API_BASE 对齐 8083 - docker/build.sh: 微调 - CLAUDE.md: 项目规范补充 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
67 lines
2.4 KiB
SQL
67 lines
2.4 KiB
SQL
-- AI Chat Service 数据库迁移
|
|
-- 创建时间: 2026-05-27
|
|
-- 说明: AI Chat Service 所需的数据库表
|
|
|
|
-- =============================================
|
|
-- 1. ai_personas (人设表)
|
|
-- =============================================
|
|
CREATE TABLE IF NOT EXISTS ai_personas (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
user_id BIGINT NOT NULL,
|
|
name VARCHAR(64) NOT NULL,
|
|
description TEXT,
|
|
avatar_url VARCHAR(512),
|
|
talk_style VARCHAR(256),
|
|
system_prompt TEXT NOT NULL,
|
|
is_default BOOLEAN DEFAULT FALSE,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- 索引
|
|
CREATE INDEX IF NOT EXISTS idx_ai_personas_user_id ON ai_personas(user_id);
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_ai_personas_user_default ON ai_personas(user_id) WHERE is_default = TRUE;
|
|
|
|
-- =============================================
|
|
-- 2. ai_user_memories (长期记忆表)
|
|
-- =============================================
|
|
CREATE TABLE IF NOT EXISTS ai_user_memories (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id BIGINT NOT NULL,
|
|
content TEXT NOT NULL,
|
|
keywords TEXT[],
|
|
weight INTEGER DEFAULT 50,
|
|
is_core BOOLEAN DEFAULT FALSE,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- 索引
|
|
CREATE INDEX IF NOT EXISTS idx_ai_user_memories_user_id ON ai_user_memories(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_ai_user_memories_keywords ON ai_user_memories USING GIN(keywords);
|
|
CREATE INDEX IF NOT EXISTS idx_ai_user_memories_weight ON ai_user_memories(weight DESC);
|
|
|
|
-- =============================================
|
|
-- 3. ai_chat_configs (配置表,存储 Dify/LLM 等配置)
|
|
-- =============================================
|
|
CREATE TABLE IF NOT EXISTS ai_chat_configs (
|
|
id SERIAL PRIMARY KEY,
|
|
config_key VARCHAR(128) UNIQUE NOT NULL,
|
|
config_value TEXT NOT NULL,
|
|
config_type VARCHAR(32) DEFAULT 'string',
|
|
category VARCHAR(64),
|
|
description VARCHAR(256),
|
|
is_encrypted BOOLEAN DEFAULT FALSE,
|
|
updated_at BIGINT,
|
|
created_at BIGINT
|
|
);
|
|
|
|
-- 索引
|
|
CREATE INDEX IF NOT EXISTS idx_ai_chat_configs_category ON ai_chat_configs(category);
|
|
|
|
-- =============================================
|
|
-- 回滚语句 (如需回滚)
|
|
-- =============================================
|
|
-- DROP TABLE IF EXISTS ai_chat_configs;
|
|
-- DROP TABLE IF EXISTS ai_user_memories;
|
|
-- DROP TABLE IF EXISTS ai_personas; |