|
| 1 | +-- 034 · Durable experimental-result trigger and stage ledger for Motif DMTA loops. |
| 2 | + |
| 3 | +BEGIN; |
| 4 | + |
| 5 | +CREATE TABLE design.motif_closed_loop_run ( |
| 6 | + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), |
| 7 | + request_key text NOT NULL UNIQUE, |
| 8 | + specification_digest bytea NOT NULL UNIQUE CHECK (octet_length(specification_digest)=32), |
| 9 | + program_id uuid NOT NULL REFERENCES design.project(id) ON DELETE RESTRICT, |
| 10 | + campaign_id uuid NOT NULL REFERENCES design.campaign(id) ON DELETE RESTRICT, |
| 11 | + endpoint_key text NOT NULL, |
| 12 | + measurement_ids uuid[] NOT NULL CHECK (cardinality(measurement_ids) > 0), |
| 13 | + specification jsonb NOT NULL, |
| 14 | + state text NOT NULL DEFAULT 'pending' |
| 15 | + CHECK (state IN ('pending','running','blocked','completed','cancelled')), |
| 16 | + stage text NOT NULL DEFAULT 'snapshot' |
| 17 | + CHECK (stage IN ('snapshot','train','predict','acquire','completed')), |
| 18 | + stage_jobs jsonb NOT NULL DEFAULT '{}'::jsonb, |
| 19 | + outputs jsonb NOT NULL DEFAULT '{}'::jsonb, |
| 20 | + attention jsonb NOT NULL DEFAULT '{}'::jsonb, |
| 21 | + actor_kind app.actor_kind NOT NULL, |
| 22 | + actor_id text NOT NULL, |
| 23 | + created_at timestamptz NOT NULL DEFAULT now(), |
| 24 | + updated_at timestamptz NOT NULL DEFAULT now(), |
| 25 | + finished_at timestamptz, |
| 26 | + CHECK (finished_at IS NULL OR finished_at >= created_at) |
| 27 | +); |
| 28 | + |
| 29 | +CREATE INDEX motif_closed_loop_claim_idx |
| 30 | + ON design.motif_closed_loop_run(state,updated_at) |
| 31 | + WHERE state IN ('pending','running'); |
| 32 | +CREATE INDEX motif_closed_loop_campaign_idx |
| 33 | + ON design.motif_closed_loop_run(campaign_id,created_at DESC); |
| 34 | + |
| 35 | +COMMENT ON TABLE design.motif_closed_loop_run IS |
| 36 | + 'Durable, replayable result->snapshot->train->predict->acquire controller state. ' |
| 37 | + 'Each scientific stage remains an ordinary Dirac Job; this table owns only orchestration.'; |
| 38 | + |
| 39 | +INSERT INTO meta.migration (filename,sha256,content_sha256,hash_source) |
| 40 | +VALUES ('034_motif_closed_loop_controller.sql','\x17feb7ca24780b808b1bea2d34bd1daf6c8bd5fe9a64d9cf02b562990916cfa5'::bytea, |
| 41 | + '\x17feb7ca24780b808b1bea2d34bd1daf6c8bd5fe9a64d9cf02b562990916cfa5'::bytea,'content') |
| 42 | +ON CONFLICT (filename) DO NOTHING; |
| 43 | + |
| 44 | +COMMIT; |
0 commit comments