muse-agent-example/数据库/迁移/V0059__检索索引代次.sql
zizi c154ca9085 配置与数据库:迁移 V0056–V0060 与流程模板
- 迁移:调用结算与配置验证(V0056)、来源当前授权(V0057)、成品补充验证回执(V0058)、检索索引代次(V0059)、
  评测单元复用来源(V0060);新表按既有约定加只追加守卫与角色授权。
- 流程模板与载入口径同步(内联保护字段改为登记类型约束);旧库迁移工具链按新表结构对齐。
- 配置:提供方模板与运行配置同步角色策略版本;角色策略白名单新增 qwen3.8-flash(见收尾报告待裁决项:
  该模型精确身份与独立性尚未核验,且策略版本号未随白名单升版)。
2026-09-18 01:15:25 +08:00

32 lines
1.4 KiB
PL/PgSQL
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.

-- B09:索引现有条目和头的事务变更守卫;不产生第二套索引或业务权威。
CREATE TABLE public.muse_method_index_guard (
singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
generation bigint NOT NULL DEFAULT 0 CHECK (generation >= 0)
);
INSERT INTO public.muse_method_index_guard (singleton, generation) VALUES (true, 0);
CREATE FUNCTION public.muse_method_index_changed() RETURNS trigger
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog AS $guard$
BEGIN
UPDATE public.muse_method_index_guard
SET generation = generation + 1
WHERE singleton;
IF NOT FOUND THEN
RAISE EXCEPTION 'method index mutation guard is missing';
END IF;
RETURN NULL;
END
$guard$;
-- statement 级别也覆盖批量改写和 TRUNCATE;事务失败时代次一并回滚。
CREATE TRIGGER muse_method_index_changed
AFTER INSERT OR UPDATE OR DELETE OR TRUNCATE ON public.muse_method_index
FOR EACH STATEMENT EXECUTE FUNCTION public.muse_method_index_changed();
CREATE TRIGGER muse_method_index_head_changed
AFTER INSERT OR UPDATE OR DELETE OR TRUNCATE ON public.muse_method_index_version
FOR EACH STATEMENT EXECUTE FUNCTION public.muse_method_index_changed();
REVOKE ALL ON public.muse_method_index_guard FROM PUBLIC, muse_app, muse_eval;
GRANT SELECT ON public.muse_method_index_guard TO muse_app, muse_eval;
REVOKE ALL ON FUNCTION public.muse_method_index_changed() FROM PUBLIC;