51 lines
2.3 KiB
SQL
51 lines
2.3 KiB
SQL
-- 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;
|