muse-agent-example/数据库/迁移/V0006__故事世界.sql
zizi 2f15c5b3bc W12 本书事实、关系与时间边界基础:本书事实、关系提案、时点边界与角色知情历史。
按 R2 串行阶段整理提交;包内文件为该阶段交付(含后续小增量),状态以工作包清单为准。
2026-09-10 19:25:41 +08:00

53 lines
2.4 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.

-- B02本书实例、不可变事实版本与提案;作者决定仍由S01保存。
CREATE TABLE public.muse_world_clock (
work_id text PRIMARY KEY REFERENCES public.muse_work(work_id),
system_revision bigint NOT NULL CHECK(system_revision>=0)
);
CREATE TABLE public.muse_world_object (
object_id text PRIMARY KEY,
work_id text NOT NULL REFERENCES public.muse_work(work_id),
type_id text NOT NULL,
instance_family text NOT NULL CHECK(instance_family IN ('entity','relation')),
current_revision bigint NOT NULL CHECK(current_revision>0)
);
CREATE TABLE public.muse_world_version (
object_id text NOT NULL REFERENCES public.muse_world_object(object_id),
revision bigint NOT NULL CHECK(revision>0),
system_revision bigint NOT NULL CHECK(system_revision>0),
content jsonb NOT NULL,
content_hash text NOT NULL,
schema_binding jsonb NOT NULL,
sources jsonb NOT NULL,
independent boolean NOT NULL,
effective_from text REFERENCES public.muse_chapter(chapter_id),
knowledge_mode text NOT NULL CHECK(knowledge_mode IN ('fact','belief','plan','setting')),
known_to jsonb NOT NULL,
reader_visible boolean NOT NULL,
planned_window jsonb,
author_id text NOT NULL,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
PRIMARY KEY(object_id,revision)
);
ALTER TABLE public.muse_world_object ADD CONSTRAINT world_current_version_fk
FOREIGN KEY(object_id,current_revision) REFERENCES public.muse_world_version(object_id,revision)
DEFERRABLE INITIALLY DEFERRED;
CREATE TABLE public.muse_fact_proposal (
proposal_id uuid PRIMARY KEY,
work_id text NOT NULL REFERENCES public.muse_work(work_id),
object_id text NOT NULL,
current_revision bigint NOT NULL CHECK(current_revision>0)
);
CREATE TABLE public.muse_fact_proposal_version (
proposal_id uuid NOT NULL REFERENCES public.muse_fact_proposal(proposal_id),
revision bigint NOT NULL CHECK(revision>0),
request jsonb NOT NULL,
proposed_content jsonb NOT NULL,
proposal_hash text NOT NULL,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
PRIMARY KEY(proposal_id,revision)
);
ALTER TABLE public.muse_fact_proposal ADD CONSTRAINT fact_proposal_current_version_fk
FOREIGN KEY(proposal_id,current_revision) REFERENCES public.muse_fact_proposal_version(proposal_id,revision)
DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX world_version_system_idx ON public.muse_world_version(object_id,system_revision DESC);