-- B10执行计划、单元归属和原始交付;任务/尝试/费用继续由S02拥有。 CREATE TABLE evaluation.muse_experiment_execution ( experiment_id uuid PRIMARY KEY REFERENCES evaluation.muse_experiment(experiment_id), request_hash text NOT NULL, plan jsonb NOT NULL, plan_hash text NOT NULL, created_at timestamptz NOT NULL DEFAULT clock_timestamp() ); CREATE TABLE evaluation.muse_evaluation_unit ( unit_id uuid PRIMARY KEY, experiment_id uuid NOT NULL REFERENCES evaluation.muse_experiment_execution(experiment_id), sample_id text NOT NULL, kind text NOT NULL CHECK(kind IN ('generation','comparison')), specification jsonb NOT NULL, specification_hash text NOT NULL, task_id uuid UNIQUE REFERENCES evaluation.muse_task(task_id) ); CREATE TABLE evaluation.muse_evaluation_output ( unit_id uuid PRIMARY KEY REFERENCES evaluation.muse_evaluation_unit(unit_id), task_id uuid NOT NULL REFERENCES evaluation.muse_task(task_id), attempt_id uuid NOT NULL, call_id text NOT NULL UNIQUE, user_input_hash text NOT NULL, output jsonb NOT NULL, output_hash text NOT NULL, evidence jsonb NOT NULL, created_at timestamptz NOT NULL DEFAULT clock_timestamp() ); CREATE TRIGGER evaluation_execution_guard BEFORE UPDATE OR DELETE ON evaluation.muse_experiment_execution FOR EACH ROW EXECUTE FUNCTION public.muse_guard_literary_history(); CREATE TRIGGER evaluation_output_guard BEFORE UPDATE OR DELETE ON evaluation.muse_evaluation_output FOR EACH ROW EXECUTE FUNCTION public.muse_guard_literary_history(); CREATE FUNCTION evaluation.muse_guard_unit_binding() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN IF TG_OP='DELETE' THEN RAISE EXCEPTION 'evaluation unit is immutable'; END IF; IF OLD.task_id IS NOT NULL OR NEW.task_id IS NULL OR (to_jsonb(OLD)-'task_id') <> (to_jsonb(NEW)-'task_id') THEN RAISE EXCEPTION 'only first task binding is allowed'; END IF; RETURN NEW; END $$; CREATE TRIGGER evaluation_unit_guard BEFORE UPDATE OR DELETE ON evaluation.muse_evaluation_unit FOR EACH ROW EXECUTE FUNCTION evaluation.muse_guard_unit_binding();