From cc5ed5d8bbb88c64a386facf0641a4f8b42e3ec7 Mon Sep 17 00:00:00 2001 From: Dotta Date: Mon, 27 Jul 2026 15:33:37 +0000 Subject: [PATCH] fix: preserve plugin run history on attribution cleanup Co-Authored-By: Paperclip --- .../db/src/migrations/0193_plugin_job_run_attribution.sql | 4 ++-- packages/db/src/schema/plugin_jobs.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/db/src/migrations/0193_plugin_job_run_attribution.sql b/packages/db/src/migrations/0193_plugin_job_run_attribution.sql index 6a22afdbd76..34285efe12e 100644 --- a/packages/db/src/migrations/0193_plugin_job_run_attribution.sql +++ b/packages/db/src/migrations/0193_plugin_job_run_attribution.sql @@ -5,13 +5,13 @@ ALTER TABLE "plugin_job_runs" ADD COLUMN IF NOT EXISTS "triggered_by_actor_id" text; ALTER TABLE "plugin_job_runs" - ADD COLUMN IF NOT EXISTS "triggered_by_agent_id" uuid REFERENCES "agents"("id"); + ADD COLUMN IF NOT EXISTS "triggered_by_agent_id" uuid REFERENCES "agents"("id") ON DELETE SET NULL; ALTER TABLE "plugin_job_runs" ADD COLUMN IF NOT EXISTS "triggered_by_user_id" text; ALTER TABLE "plugin_job_runs" - ADD COLUMN IF NOT EXISTS "triggered_by_run_id" uuid REFERENCES "heartbeat_runs"("id"); + ADD COLUMN IF NOT EXISTS "triggered_by_run_id" uuid REFERENCES "heartbeat_runs"("id") ON DELETE SET NULL; ALTER TABLE "plugin_job_runs" ADD COLUMN IF NOT EXISTS "responsible_user_id" text; diff --git a/packages/db/src/schema/plugin_jobs.ts b/packages/db/src/schema/plugin_jobs.ts index 972ec35f3f3..547e67e3d28 100644 --- a/packages/db/src/schema/plugin_jobs.ts +++ b/packages/db/src/schema/plugin_jobs.ts @@ -92,11 +92,11 @@ export const pluginJobRuns = pgTable( /** Host-derived actor id that triggered this run, when not scheduler-owned. */ triggeredByActorId: text("triggered_by_actor_id"), /** Host-derived agent id that triggered this run, when applicable. */ - triggeredByAgentId: uuid("triggered_by_agent_id").references(() => agents.id), + triggeredByAgentId: uuid("triggered_by_agent_id").references(() => agents.id, { onDelete: "set null" }), /** Host-derived board/user id that triggered this run, when applicable. */ triggeredByUserId: text("triggered_by_user_id"), /** Host-derived heartbeat run id that triggered this run, when applicable. */ - triggeredByRunId: uuid("triggered_by_run_id").references(() => heartbeatRuns.id), + triggeredByRunId: uuid("triggered_by_run_id").references(() => heartbeatRuns.id, { onDelete: "set null" }), /** Responsible user resolved by the host for this run, when known. */ responsibleUserId: text("responsible_user_id"), /** Current lifecycle state of this run. */