diff --git a/front/lib/api/assistant/conversation/destroy.ts b/front/lib/api/assistant/conversation/destroy.ts index dab4315716f9..3f8cec95d33a 100644 --- a/front/lib/api/assistant/conversation/destroy.ts +++ b/front/lib/api/assistant/conversation/destroy.ts @@ -8,6 +8,7 @@ import { AgentProcessAction } from "@app/lib/models/assistant/actions/process"; import { AgentRetrievalAction } from "@app/lib/models/assistant/actions/retrieval"; import { AgentTablesQueryAction } from "@app/lib/models/assistant/actions/tables_query"; import { AgentWebsearchAction } from "@app/lib/models/assistant/actions/websearch"; +import { AgentMessageContent } from "@app/lib/models/assistant/agent_message_content"; import type { Conversation } from "@app/lib/models/assistant/conversation"; import { AgentMessage, @@ -156,6 +157,9 @@ export async function destroyConversation( await UserMessage.destroy({ where: { id: userMessageIds }, }); + await AgentMessageContent.destroy({ + where: { agentMessageId: agentMessageIds }, + }); await AgentMessageFeedback.destroy({ where: { agentMessageId: agentMessageIds }, }); diff --git a/front/lib/models/assistant/agent_message_content.ts b/front/lib/models/assistant/agent_message_content.ts index 0fe209be3eee..dff73e28ef48 100644 --- a/front/lib/models/assistant/agent_message_content.ts +++ b/front/lib/models/assistant/agent_message_content.ts @@ -58,7 +58,8 @@ AgentMessageContent.belongsTo(AgentMessage, { name: "agentMessageId", allowNull: false, }, - onDelete: "CASCADE", + onDelete: "RESTRICT", + onUpdate: "RESTRICT", }); AgentMessage.hasMany(AgentMessageContent, { @@ -67,5 +68,6 @@ AgentMessage.hasMany(AgentMessageContent, { name: "agentMessageId", allowNull: false, }, - onDelete: "CASCADE", + onDelete: "RESTRICT", + onUpdate: "RESTRICT", }); diff --git a/front/migrations/db/migration_128.sql b/front/migrations/db/migration_128.sql new file mode 100644 index 000000000000..f37b194c38d5 --- /dev/null +++ b/front/migrations/db/migration_128.sql @@ -0,0 +1,7 @@ +ALTER TABLE "agent_message_contents" + DROP CONSTRAINT "agent_message_contents_agentMessageId_fkey", + ADD CONSTRAINT "agent_message_contents_agentMessageId_fkey" + FOREIGN KEY ("agentMessageId") + REFERENCES "agent_messages"("id") + ON DELETE RESTRICT + ON UPDATE RESTRICT; \ No newline at end of file diff --git a/front/poke/temporal/activities.ts b/front/poke/temporal/activities.ts index 6d9511ad0703..4473b3bd79e7 100644 --- a/front/poke/temporal/activities.ts +++ b/front/poke/temporal/activities.ts @@ -63,6 +63,7 @@ import { UserMetadataModel } from "@app/lib/resources/storage/models/user"; import { UserResource } from "@app/lib/resources/user_resource"; import { renderLightWorkspaceType } from "@app/lib/workspace"; import logger from "@app/logger/logger"; +import { AgentMessageContent } from "@app/lib/models/assistant/agent_message_content"; const hardDeleteLogger = logger.child({ activity: "hard-delete" }); @@ -237,6 +238,11 @@ export async function deleteConversationsActivity({ }); } + await AgentMessageContent.destroy({ + where: { agentMessageId: agentMessage.id }, + transaction: t, + }); + await AgentMessageFeedback.destroy({ where: { agentMessageId: agentMessage.id }, transaction: t,