Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(db): revert agent.runtimeId to nullable + SET NULL
Gener9c8694ebb25a
diff --git a/src/shared/src/db/queries/agent.ts b/src/shared/src/db/queries/agent.tsindex 1c970ccf3..ec23c8093 100644--- a/src/shared/src/db/queries/agent.ts+++ b/src/shared/src/db/queries/agent.ts@@ -50,10 +50,10 @@ export async function createAgent(data: {workspaceId: string;name: string;- runtimeId: string;description?: string;instructions?: string;avatarUrl?: string | null;+ runtimeId?: string | null;runtimeMode?: string;runtimeConfig?: unknown;visibility?: string;@@ -69,7 +69,7 @@ export async function createAgent(.values({workspaceId: data.workspaceId,name: data.name,- runtimeId: data.runtimeId,+ runtimeId: data.runtimeId ?? null,description: data.description ?? "",instructions: data.instructions ?? "",avatarUrl: data.avatarUrl ?? null,@@ -109,7 +109,7 @@ export async function updateAgent(name?: string;description?: string;instructions?: string;- runtimeId?: string;+ runtimeId?: string | null;runtimeConfig?: unknown;visibility?: string;},diff --git a/src/shared/src/db/schema.ts b/src/shared/src/db/schema.tsindex 71bd67ebc..5edf7e450 100644--- a/src/shared/src/db/schema.ts+++ b/src/shared/src/db/schema.ts@@ -211,9 +211,7 @@ export const agent = sqliteTable(description: text("description").notNull().default(""),instructions: text("instructions").notNull().default(""),avatarUrl: text("avatar_url"),- runtimeId: text("runtime_id")- .notNull()- .references(() => agentRuntime.id, { onDelete: "cascade" }),+ runtimeId: text("runtime_id").references(() => agentRuntime.id, { onDelete: "set null" }),runtimeMode: text("runtime_mode").notNull().default("local"),runtimeConfig: text("runtime_config", { mode: "json" }),visibility: text("visibility").notNull().default("private"),diff --git a/src/web/migrations/0018_schema_cascade_cleanup.sql b/src/web/migrations/0018_schema_cascade_cleanup.sqlindex 42dc92067..495c431d3 100644--- a/src/web/migrations/0018_schema_cascade_cleanup.sql+++ b/src/web/migrations/0018_schema_cascade_cleanup.sql@@ -1,5 +1,5 @@-- Fix FK cascade behavior for agent and workspace_file_request tables:--- 1. agent.runtime_id: NOT NULL + ON DELETE CASCADE — agent cannot exist without runtime+-- 1. agent.runtime_id: nullable + ON DELETE SET NULL — runtime removal keeps agent alive-- 2. agent.owner_id: ON DELETE CASCADE — deleting user deletes their agents-- 3. workspace_file_request: add composite FK to agent(id, workspace_id) ON DELETE CASCADE@@ -13,7 +13,7 @@ CREATE TABLE agent_new (description TEXT NOT NULL DEFAULT '',instructions TEXT NOT NULL DEFAULT '',avatar_url TEXT,- runtime_id TEXT NOT NULL REFERENCES agent_runtime(id) ON DELETE CASCADE,+ runtime_id TEXT REFERENCES agent_runtime(id) ON DELETE SET NULL,runtime_mode TEXT NOT NULL DEFAULT 'local',runtime_config TEXT,visibility TEXT NOT NULL DEFAULT 'private',@@ -28,9 +28,6 @@ CREATE TABLE agent_new (PRIMARY KEY (id, workspace_id));--- Clean up orphan agents with NULL runtime_id (previously set by deleteRuntimesByDaemonId)-DELETE FROM agent WHERE runtime_id IS NULL;-INSERT INTO agent_new SELECT * FROM agent;DROP TABLE agent;