muse-agent-example/数据库/迁移/V0007__资料研究.sql
zizi f76c3cd04a docs(架构): 归档R2历史留痕并清理过程计划与实施分期标签
- 归档并收敛 R2 历史留痕至 docs/实现回顾/R2改造历史留痕.md,删除已退出生命周期的改造计划、旧文件处置及验证过程文档
- 现行测试用例身份收敛至 tests/用例清单.json(1358条扁平登记),适配 conftest、索引维护与测试执行验证
- 清理源码、配置、SQL迁移头、测试夹具及规则文档中的 Wxx 实施分期标签与过时过程描述
- 同步重新打包构建资源清单,通过全量离线测试、模块边界、类型检查与索引双向强核验
2026-09-16 19:09:14 +08:00

68 lines
3.1 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.

-- B03:外部与私人资料、原文版本、清理候选与榜单快照。
-- 原文只追加不可改写;清理是对照产物;榜单快照把时点观察与效果推断分开(无 run 归因字段)。
DO $migration$
BEGIN
-- 来源:同源再导入落到版本链;kind 区分作者稿、参考书、网页、笔记与灵感。
CREATE TABLE public.muse_source (
source_id uuid PRIMARY KEY,
kind text NOT NULL CHECK (kind IN ('author_draft','reference','web','note','inspiration')),
title text NOT NULL,
origin text NOT NULL,
authorized_uses jsonb NOT NULL DEFAULT '[]'::jsonb,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
UNIQUE (origin, kind),
CHECK (jsonb_typeof(authorized_uses) = 'array')
);
-- 原文版本:只追加;内容哈希用于证据校验与重复辨认。
CREATE TABLE public.muse_source_version (
source_id uuid NOT NULL REFERENCES public.muse_source(source_id),
revision bigint NOT NULL CHECK (revision > 0),
content_hash text NOT NULL,
content text NOT NULL,
import_result jsonb NOT NULL,
imported_at timestamptz NOT NULL DEFAULT clock_timestamp(),
PRIMARY KEY (source_id, revision),
CHECK (jsonb_typeof(import_result) = 'object')
);
CREATE INDEX ON public.muse_source_version (source_id, imported_at);
-- 清理候选:对照产物,原文不受影响;删除项可定位、可回退。
CREATE TABLE public.muse_clean_candidate (
candidate_id uuid PRIMARY KEY,
source_id uuid NOT NULL REFERENCES public.muse_source(source_id),
revision bigint NOT NULL,
removals jsonb NOT NULL,
status text NOT NULL CHECK (status IN ('proposed','applied','rejected')),
cleaned_hash text,
cleaned_text text,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
UNIQUE (source_id, revision, candidate_id),
CHECK (jsonb_typeof(removals) = 'array'),
CHECK ((status = 'applied') = (cleaned_hash IS NOT NULL AND cleaned_text IS NOT NULL)),
FOREIGN KEY (source_id, revision) REFERENCES public.muse_source_version(source_id, revision)
);
-- 榜单来源登记:具名榜种与采集方式。
CREATE TABLE public.muse_ranking_source (
ranking_id text PRIMARY KEY,
name text NOT NULL,
url text NOT NULL,
采集方式 text NOT NULL
);
-- 榜单快照:时刻观察;失败保留失败态;不携带任何 run 归因。
CREATE TABLE public.muse_ranking_snapshot (
snapshot_id uuid PRIMARY KEY,
ranking_id text NOT NULL REFERENCES public.muse_ranking_source(ranking_id),
captured_at timestamptz NOT NULL DEFAULT clock_timestamp(),
status text NOT NULL CHECK (status IN ('ok','failed')),
failure_reason text,
items jsonb,
CHECK ((status = 'ok') = (items IS NOT NULL)),
CHECK (items IS NULL OR jsonb_typeof(items) = 'array')
);
CREATE INDEX ON public.muse_ranking_snapshot (ranking_id, captured_at DESC);
END
$migration$;