Files
streamline/drizzle/0003_run_conditions.sql
T
2026-11-16 17:26:44 -08:00

46 lines
1.7 KiB
SQL

-- Execution conditions replace spec deltas.
--
-- Hand-written rather than drizzle-kit generated: the generator sees one table
-- removed and one added and asks interactively whether it's a rename. It is NOT
-- a rename — the columns changed meaning (from "diff against the draft" to "the
-- condition itself"), so a rename would leave rows whose `op`/`original`/`actual`
-- semantics no longer exist. An explicit DROP + CREATE says that.
--
-- Dropping spec_delta_events is safe here: it was verified empty (0 rows) before
-- this ran — nothing was ever captured, because every eligible run landed on a
-- node whose bundle predated the capture endpoint. Nothing to migrate.
CREATE TABLE IF NOT EXISTS "run_conditions" (
"id" text PRIMARY KEY NOT NULL,
"target_kind" text NOT NULL,
"target_id" text NOT NULL,
"node_id" text,
"round" bigint NOT NULL,
"source" text NOT NULL,
"kind" text NOT NULL,
"scope" text NOT NULL,
"subject" text NOT NULL,
"statement" text NOT NULL,
"payload" text,
"verdict" text NOT NULL,
"spec" text NOT NULL,
"spec_said" text,
"evidence" text,
"ts" bigint NOT NULL,
"ingested_at" bigint NOT NULL,
"promoted_at" bigint
);
--> statement-breakpoint
-- Retrieval filters on (target_kind, target_id) for the per-task view, and on
-- (scope, subject, kind) when arbitration looks for a colliding condition.
CREATE INDEX IF NOT EXISTS "run_conditions_target_idx"
ON "run_conditions" ("target_kind", "target_id");
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "run_conditions_subject_idx"
ON "run_conditions" ("scope", "subject", "kind");
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "run_conditions_ts_idx"
ON "run_conditions" ("ts");
--> statement-breakpoint
DROP TABLE IF EXISTS "spec_delta_events";