muse-agent-example/数据库/迁移/V0009__正文写作.sql
zizi 8353d11d40 W10 作品骨架与人工正文版本:作品/章节骨架、目录版本与人工正文版本链。
按 R2 串行阶段整理提交;包内文件为该阶段交付(含后续小增量),状态以工作包清单为准。
2026-09-10 19:25:41 +08:00

51 lines
2.3 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.

-- B05正文版本只追加;段落身份与显式换行保留在受限文档树中。
CREATE TABLE public.muse_document (
document_id uuid PRIMARY KEY,
chapter_id text NOT NULL REFERENCES public.muse_chapter(chapter_id),
branch_id text NOT NULL,
current_revision bigint NOT NULL CHECK(current_revision>0),
UNIQUE(chapter_id,branch_id)
);
CREATE TABLE public.muse_document_version (
document_id uuid NOT NULL REFERENCES public.muse_document(document_id),
revision bigint NOT NULL CHECK(revision>0),
document jsonb NOT NULL,
document_hash text NOT NULL,
visible_text_hash text NOT NULL,
author_id text NOT NULL,
restored_from bigint,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
PRIMARY KEY(document_id,revision),
FOREIGN KEY(document_id,restored_from) REFERENCES public.muse_document_version(document_id,revision)
);
ALTER TABLE public.muse_document ADD CONSTRAINT document_current_version_fk
FOREIGN KEY(document_id,current_revision) REFERENCES public.muse_document_version(document_id,revision)
DEFERRABLE INITIALLY DEFERRED;
-- 作者改稿先存候选,决定记录由S01拥有;生成候选的证据绑定由后续写作任务扩展。
CREATE TABLE public.muse_writing_candidate (
candidate_id uuid PRIMARY KEY,
chapter_id text NOT NULL REFERENCES public.muse_chapter(chapter_id),
branch_id text NOT NULL,
origin text NOT NULL CHECK(origin='author'),
current_revision bigint NOT NULL CHECK(current_revision>0)
);
CREATE TABLE public.muse_writing_candidate_version (
candidate_id uuid NOT NULL REFERENCES public.muse_writing_candidate(candidate_id),
revision bigint NOT NULL CHECK(revision>0),
base_revision bigint NOT NULL CHECK(base_revision>=0),
base_hash text NOT NULL,
document jsonb NOT NULL,
document_hash text NOT NULL,
visible_text_hash text NOT NULL,
candidate_hash text NOT NULL,
checks jsonb NOT NULL,
author_id text NOT NULL,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
PRIMARY KEY(candidate_id,revision)
);
ALTER TABLE public.muse_writing_candidate ADD CONSTRAINT writing_candidate_version_fk
FOREIGN KEY(candidate_id,current_revision)
REFERENCES public.muse_writing_candidate_version(candidate_id,revision)
DEFERRABLE INITIALLY DEFERRED;