muse-agent-example/数据库/迁移/V0021__模型候选与审校报告.sql

60 lines
2.9 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.

-- W15(B05/B06):模型候选来源证据与审校报告;候选来源在作者改稿之外扩展模型生成。
-- 模型候选不走 S01 作者决定命令,由写作任务在任务运行事务内写入;作者决定仍归 S01。
-- B05/B06 正式内容表只在 public 命名空间(与 V0009 一致)。
DO $migration$
DECLARE
origin_constraint text;
BEGIN
SELECT conname INTO origin_constraint
FROM pg_constraint
WHERE conrelid = 'public.muse_writing_candidate'::regclass
AND contype = 'c'
AND pg_get_constraintdef(oid) ILIKE '%origin%';
IF origin_constraint IS NULL THEN
RAISE EXCEPTION '候选来源约束缺失,不能盲目扩展';
END IF;
EXECUTE format($ddl$
ALTER TABLE public.muse_writing_candidate DROP CONSTRAINT %I;
ALTER TABLE public.muse_writing_candidate
ADD CONSTRAINT writing_candidate_origin_check
CHECK (origin IN ('author', 'model'));
-- 模型候选的证据绑定:来源任务、冻结快照与处理器/模型回执哈希;一行绑定一个候选,不可改写。
CREATE TABLE public.muse_model_candidate (
candidate_id uuid PRIMARY KEY
REFERENCES public.muse_writing_candidate(candidate_id),
task_id uuid NOT NULL REFERENCES public.muse_task(task_id),
snapshot_id uuid NOT NULL REFERENCES public.muse_context_snapshot(snapshot_id),
flow_version text NOT NULL,
processor_versions jsonb NOT NULL,
model_evidence jsonb NOT NULL,
prompt_hashes jsonb NOT NULL,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
CHECK (jsonb_typeof(processor_versions) = 'object'),
CHECK (jsonb_typeof(model_evidence) = 'array'),
CHECK (jsonb_typeof(prompt_hashes) = 'object')
);
-- 审校报告:绑定候选版本与所依据快照;问题与覆盖只追加,不修改候选本身。
CREATE TABLE public.muse_review_report (
report_id uuid PRIMARY KEY,
candidate_id uuid NOT NULL
REFERENCES public.muse_writing_candidate(candidate_id),
candidate_revision bigint NOT NULL CHECK (candidate_revision > 0),
snapshot_id uuid NOT NULL
REFERENCES public.muse_context_snapshot(snapshot_id),
basic jsonb NOT NULL,
continuity jsonb NOT NULL,
verdict text NOT NULL CHECK (verdict IN ('passed', 'failed')),
coverage jsonb NOT NULL,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
UNIQUE (candidate_id, candidate_revision),
CHECK (basic ? ALL (ARRAY['checks', 'verdict'])),
CHECK (continuity ? ALL (ARRAY['findings', 'coverage'])),
CHECK (jsonb_typeof(coverage) = 'object')
);
CREATE INDEX ON public.muse_review_report (candidate_id, created_at);
$ddl$, origin_constraint);
END
$migration$;