30 lines
1.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================================
-- 表16documents文档存储表
-- 用途Notion导出存储支持嵌套结构和树形路径
-- 导入工作流:霜砚整理 → Notion API导出 → 写入本地documents表
-- ============================================================
CREATE TABLE IF NOT EXISTS documents (
document_id VARCHAR(64) PRIMARY KEY,
persona_id VARCHAR(32)
REFERENCES persona_identity(persona_id),
parent_id VARCHAR(64) REFERENCES documents(document_id),
path TEXT NOT NULL, -- 树形路径,如 "/root/folder/doc"
title VARCHAR(256) NOT NULL,
content TEXT, -- markdown内容
content_type VARCHAR(32) NOT NULL DEFAULT 'markdown'
CHECK (content_type IN ('markdown', 'json', 'plain', 'notion')),
source VARCHAR(32) NOT NULL DEFAULT 'local'
CHECK (source IN ('local', 'notion_import', 'api')),
tags TEXT, -- JSON array
version INTEGER NOT NULL DEFAULT 1,
checksum VARCHAR(64),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_doc_persona ON documents(persona_id);
CREATE INDEX IF NOT EXISTS idx_doc_parent ON documents(parent_id);
CREATE INDEX IF NOT EXISTS idx_doc_path ON documents(path);
CREATE INDEX IF NOT EXISTS idx_doc_source ON documents(source);