muse-agent-example/数据库/迁移/V0020__上下文快照与消费.sql
zizi f76c3cd04a docs(架构): 归档R2历史留痕并清理过程计划与实施分期标签
- 归档并收敛 R2 历史留痕至 docs/实现回顾/R2改造历史留痕.md,删除已退出生命周期的改造计划、旧文件处置及验证过程文档
- 现行测试用例身份收敛至 tests/用例清单.json(1358条扁平登记),适配 conftest、索引维护与测试执行验证
- 清理源码、配置、SQL迁移头、测试夹具及规则文档中的 Wxx 实施分期标签与过时过程描述
- 同步重新打包构建资源清单,通过全量离线测试、模块边界、类型检查与索引双向强核验
2026-09-16 19:09:14 +08:00

29 lines
1.2 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.

-- B09:任务范围与实际消费的不可变上下文快照。
-- 快照身份由载荷确定性派生,同一输入重复冻结幂等为一行;历史快照只读不改写。
DO $migration$
DECLARE
namespace text;
BEGIN
FOREACH namespace IN ARRAY ARRAY['public', 'evaluation'] LOOP
EXECUTE format($ddl$
CREATE TABLE %1$I.muse_context_snapshot (
snapshot_id uuid PRIMARY KEY,
run_purpose public.muse_purpose NOT NULL,
task_id uuid NOT NULL REFERENCES %1$I.muse_task(task_id),
work_id text NOT NULL,
input_hash text NOT NULL,
frozen_scope jsonb NOT NULL,
assembly jsonb NOT NULL,
source_bindings jsonb NOT NULL,
created_by text NOT NULL,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
UNIQUE (run_purpose, task_id, input_hash),
CHECK (assembly ? ALL (ARRAY['入选','省略','字节数','文本哈希','文本'])),
CHECK (jsonb_typeof(source_bindings) = 'array')
);
CREATE INDEX ON %1$I.muse_context_snapshot (task_id, created_at);
$ddl$, namespace);
END LOOP;
END
$migration$;