muse-agent-example/数据库/迁移/V0020__上下文快照与消费.sql

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

-- W14 回合2(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$;