- 归档并收敛 R2 历史留痕至 docs/实现回顾/R2改造历史留痕.md,删除已退出生命周期的改造计划、旧文件处置及验证过程文档 - 现行测试用例身份收敛至 tests/用例清单.json(1358条扁平登记),适配 conftest、索引维护与测试执行验证 - 清理源码、配置、SQL迁移头、测试夹具及规则文档中的 Wxx 实施分期标签与过时过程描述 - 同步重新打包构建资源清单,通过全量离线测试、模块边界、类型检查与索引双向强核验
130 lines
6.1 KiB
SQL
130 lines
6.1 KiB
SQL
-- B04:方法候选与版本、证据反例、固定绑定、不可变消费与检索索引。
|
||
-- 方法是跨作品正式内容:版本只追加;绑定记具体版本不追随;消费不可变;索引可重建不动正式内容。
|
||
-- 裁决 A:向量不依赖 pgvector,存 double precision[],相似度在应用层计算。
|
||
DO $migration$
|
||
BEGIN
|
||
-- 方法:跨作品范式卡;内容哈希按 owner 去重,同哈希不同 owner 由服务层拒绝。
|
||
CREATE TABLE public.muse_method (
|
||
method_id uuid PRIMARY KEY,
|
||
owner text NOT NULL,
|
||
type_id text NOT NULL,
|
||
title text NOT NULL,
|
||
state text NOT NULL CHECK (state IN ('proposed','confirmed','enabled','disabled','withdrawn')),
|
||
content_hash text NOT NULL,
|
||
current_version bigint NOT NULL DEFAULT 0 CHECK (current_version >= 0),
|
||
created_by text NOT NULL,
|
||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||
updated_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||
UNIQUE (owner, content_hash),
|
||
CHECK (title <> '')
|
||
);
|
||
CREATE INDEX ON public.muse_method (type_id, state);
|
||
|
||
-- 方法版本:append-only;绑定与消费都指向具体版本。
|
||
CREATE TABLE public.muse_method_version (
|
||
version_id uuid PRIMARY KEY,
|
||
method_id uuid NOT NULL REFERENCES public.muse_method(method_id),
|
||
version bigint NOT NULL CHECK (version > 0),
|
||
content jsonb NOT NULL CHECK (jsonb_typeof(content) = 'object'),
|
||
content_hash text NOT NULL,
|
||
参数上限 jsonb NOT NULL CHECK (jsonb_typeof(参数上限) = 'object'),
|
||
schema_id text NOT NULL,
|
||
schema_version int NOT NULL,
|
||
effective_schema_hash text NOT NULL,
|
||
proposal_id uuid,
|
||
confirmed_by text NOT NULL,
|
||
confirmed_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||
UNIQUE (method_id, version),
|
||
UNIQUE (method_id, content_hash)
|
||
);
|
||
|
||
-- 方法提案:审阅对象;确认后版本入 append-only 表,提案保留可追溯。
|
||
CREATE TABLE public.muse_method_proposal (
|
||
proposal_id uuid PRIMARY KEY,
|
||
method_id uuid NOT NULL,
|
||
revision bigint NOT NULL CHECK (revision >= 1),
|
||
request jsonb NOT NULL CHECK (jsonb_typeof(request) = 'object'),
|
||
proposal_hash text NOT NULL,
|
||
created_by text NOT NULL,
|
||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||
UNIQUE (method_id, revision)
|
||
);
|
||
|
||
-- 证据与反例:来源(B03 版本钉住)、样例、反例、例外与静态方法资源引用(不复制正文)。
|
||
CREATE TABLE public.muse_method_evidence (
|
||
evidence_id uuid PRIMARY KEY,
|
||
method_id uuid NOT NULL REFERENCES public.muse_method(method_id),
|
||
kind text NOT NULL CHECK (kind IN ('source','sample','counter','exception','static_ref')),
|
||
ref jsonb NOT NULL CHECK (jsonb_typeof(ref) = 'object'),
|
||
note text NOT NULL DEFAULT '',
|
||
created_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
||
);
|
||
CREATE INDEX ON public.muse_method_evidence (method_id, kind);
|
||
|
||
-- 方法绑定:作品或规划目标固定到具体版本;active 唯一;重绑留痕可回查。
|
||
CREATE TABLE public.muse_method_binding (
|
||
binding_id uuid PRIMARY KEY,
|
||
work_id text NOT NULL,
|
||
target_kind text NOT NULL CHECK (target_kind IN ('work','planning')),
|
||
target_ref text NOT NULL,
|
||
method_id uuid NOT NULL REFERENCES public.muse_method(method_id),
|
||
version_id uuid NOT NULL REFERENCES public.muse_method_version(version_id),
|
||
bound_by text NOT NULL,
|
||
bound_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||
released_at timestamptz,
|
||
CHECK (target_ref <> '')
|
||
);
|
||
CREATE UNIQUE INDEX muse_method_binding_active
|
||
ON public.muse_method_binding (work_id, target_ref, method_id)
|
||
WHERE released_at IS NULL;
|
||
|
||
-- 方法消费:不可变;kind 区分生成/审阅/规划/启用验证;上下文与结果都可定位。
|
||
CREATE TABLE public.muse_method_usage (
|
||
usage_id uuid PRIMARY KEY,
|
||
method_version_id uuid NOT NULL REFERENCES public.muse_method_version(version_id),
|
||
kind text NOT NULL CHECK (kind IN ('generation','review','planning','enablement')),
|
||
context_ref text NOT NULL,
|
||
fragment_hash text NOT NULL,
|
||
result_ref text,
|
||
task_id uuid,
|
||
created_by text NOT NULL,
|
||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||
UNIQUE (method_version_id, kind, context_ref, fragment_hash)
|
||
);
|
||
CREATE INDEX ON public.muse_method_usage (method_version_id, created_at);
|
||
|
||
-- 方法检索索引:每版本一向量;embedder 版本随行;重建整表重写,不动方法本体。
|
||
CREATE TABLE public.muse_method_index (
|
||
method_version_id uuid PRIMARY KEY REFERENCES public.muse_method_version(version_id),
|
||
检索文本 text NOT NULL,
|
||
检索文本哈希 text NOT NULL,
|
||
vector double precision[] NOT NULL CHECK (array_length(vector, 1) > 0),
|
||
embedder text NOT NULL,
|
||
built_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
||
);
|
||
|
||
-- 索引版本台账:当前有效索引身份;检索时对不上即拒绝为陈旧。
|
||
CREATE TABLE public.muse_method_index_version (
|
||
ledger_id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||
索引身份 text NOT NULL,
|
||
embedder text NOT NULL,
|
||
method_count int NOT NULL CHECK (method_count >= 0),
|
||
built_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||
active boolean NOT NULL DEFAULT false
|
||
);
|
||
CREATE UNIQUE INDEX muse_method_index_active ON public.muse_method_index_version (active)
|
||
WHERE active;
|
||
|
||
-- 文档派生索引:承接章后流程登记的摘要绑定,关键词可查。
|
||
CREATE TABLE public.muse_document_index (
|
||
document_id text NOT NULL,
|
||
revision bigint NOT NULL CHECK (revision >= 0),
|
||
document_hash text NOT NULL,
|
||
结构哈希 text NOT NULL,
|
||
summary text NOT NULL DEFAULT '',
|
||
registered_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||
PRIMARY KEY (document_id, revision)
|
||
);
|
||
END
|
||
$migration$;
|