Files
insightflow/backend/schema.sql

74 lines
2.3 KiB
SQL

-- InsightFlow Phase 3 - Database Schema
-- 支持知识生长与多文件融合
-- 项目表
CREATE TABLE IF NOT EXISTS projects (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 文件/转录表
CREATE TABLE IF NOT EXISTS transcripts (
id TEXT PRIMARY KEY,
project_id TEXT NOT NULL,
filename TEXT,
full_text TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES projects(id)
);
-- 全局实体表(跨文件共享)
CREATE TABLE IF NOT EXISTS entities (
id TEXT PRIMARY KEY,
project_id TEXT NOT NULL,
name TEXT NOT NULL,
canonical_name TEXT, -- 规范名称(用于对齐)
type TEXT,
definition TEXT,
aliases TEXT, -- JSON 数组:["别名1", "别名2"]
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES projects(id)
);
-- 实体提及表(文件中的具体位置)
CREATE TABLE IF NOT EXISTS entity_mentions (
id TEXT PRIMARY KEY,
entity_id TEXT NOT NULL,
transcript_id TEXT NOT NULL,
start_pos INTEGER,
end_pos INTEGER,
text_snippet TEXT,
confidence REAL DEFAULT 1.0,
FOREIGN KEY (entity_id) REFERENCES entities(id),
FOREIGN KEY (transcript_id) REFERENCES transcripts(id)
);
-- 实体关系表
CREATE TABLE IF NOT EXISTS entity_relations (
id TEXT PRIMARY KEY,
project_id TEXT NOT NULL,
source_entity_id TEXT NOT NULL,
target_entity_id TEXT NOT NULL,
relation_type TEXT, -- "belongs_to", "works_with", "depends_on" 等
evidence TEXT, -- 关系来源文本
transcript_id TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES projects(id),
FOREIGN KEY (source_entity_id) REFERENCES entities(id),
FOREIGN KEY (target_entity_id) REFERENCES entities(id)
);
-- 术语表(项目级热词,用于 ASR 优化)
CREATE TABLE IF NOT EXISTS glossary (
id TEXT PRIMARY KEY,
project_id TEXT NOT NULL,
term TEXT NOT NULL,
pronunciation TEXT, -- 发音提示,如 "K8s" -> "Kubernetes"
frequency INTEGER DEFAULT 1,
FOREIGN KEY (project_id) REFERENCES projects(id)
);