-- 全书声音候选与确认版本;人物语言指纹仍归B02。 CREATE TABLE public.muse_voice_proposal ( proposal_id uuid PRIMARY KEY, author_id text NOT NULL, work_id text NOT NULL REFERENCES public.muse_work(work_id), revision bigint NOT NULL DEFAULT 1 CHECK (revision = 1), base_revision bigint NOT NULL CHECK (base_revision >= 0), request jsonb NOT NULL CHECK (jsonb_typeof(request) = 'object'), proposal_hash text NOT NULL, created_at timestamptz NOT NULL DEFAULT clock_timestamp() ); CREATE TABLE public.muse_voice_version ( version_id uuid PRIMARY KEY, work_id text NOT NULL REFERENCES public.muse_work(work_id), revision bigint NOT NULL CHECK (revision > 0), proposal_id uuid NOT NULL UNIQUE REFERENCES public.muse_voice_proposal(proposal_id), content_hash text NOT NULL, effective_schema_hash text NOT NULL, projection_version text NOT NULL, created_at timestamptz NOT NULL DEFAULT clock_timestamp(), UNIQUE (work_id, revision), UNIQUE (work_id, version_id) ); CREATE TABLE public.muse_voice_current ( work_id text PRIMARY KEY REFERENCES public.muse_work(work_id), version_id uuid NOT NULL, FOREIGN KEY (work_id, version_id) REFERENCES public.muse_voice_version(work_id, version_id) ); CREATE FUNCTION public.muse_guard_voice_history() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION '声音提案与历史版本只追加,不改写或删除'; END; $$; CREATE TRIGGER muse_voice_proposal_guard BEFORE UPDATE OR DELETE ON public.muse_voice_proposal FOR EACH ROW EXECUTE FUNCTION public.muse_guard_voice_history(); CREATE TRIGGER muse_voice_version_guard BEFORE UPDATE OR DELETE ON public.muse_voice_version FOR EACH ROW EXECUTE FUNCTION public.muse_guard_voice_history();