Skip to content

Commit ede224a

Browse files
aadamgoughAdam Gough
andauthored
fix(mem-deletion): hard deletion of memory (#622)
* fix: memory deletion * fix: bun run lint --------- Co-authored-by: Adam Gough <adamgough@Adams-MacBook-Pro.local>
1 parent 5cf7d02 commit ede224a

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

apps/sim/app/api/memory/[id]/route.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { and, eq, isNull } from 'drizzle-orm'
1+
import { and, eq } from 'drizzle-orm'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { createLogger } from '@/lib/logs/console-logger'
44
import { db } from '@/db'
@@ -40,7 +40,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
4040
const memories = await db
4141
.select()
4242
.from(memory)
43-
.where(and(eq(memory.key, id), eq(memory.workflowId, workflowId), isNull(memory.deletedAt)))
43+
.where(and(eq(memory.key, id), eq(memory.workflowId, workflowId)))
4444
.orderBy(memory.createdAt)
4545
.limit(1)
4646

@@ -112,7 +112,7 @@ export async function DELETE(
112112
const existingMemory = await db
113113
.select({ id: memory.id })
114114
.from(memory)
115-
.where(and(eq(memory.key, id), eq(memory.workflowId, workflowId), isNull(memory.deletedAt)))
115+
.where(and(eq(memory.key, id), eq(memory.workflowId, workflowId)))
116116
.limit(1)
117117

118118
if (existingMemory.length === 0) {
@@ -128,14 +128,8 @@ export async function DELETE(
128128
)
129129
}
130130

131-
// Soft delete by setting deletedAt timestamp
132-
await db
133-
.update(memory)
134-
.set({
135-
deletedAt: new Date(),
136-
updatedAt: new Date(),
137-
})
138-
.where(and(eq(memory.key, id), eq(memory.workflowId, workflowId)))
131+
// Hard delete the memory
132+
await db.delete(memory).where(and(eq(memory.key, id), eq(memory.workflowId, workflowId)))
139133

140134
logger.info(`[${requestId}] Memory deleted successfully: ${id} for workflow: ${workflowId}`)
141135
return NextResponse.json(
@@ -202,7 +196,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
202196
const existingMemories = await db
203197
.select()
204198
.from(memory)
205-
.where(and(eq(memory.key, id), eq(memory.workflowId, workflowId), isNull(memory.deletedAt)))
199+
.where(and(eq(memory.key, id), eq(memory.workflowId, workflowId)))
206200
.limit(1)
207201

208202
if (existingMemories.length === 0) {
@@ -250,13 +244,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
250244
}
251245

252246
// Update the memory with new data
253-
await db
254-
.update(memory)
255-
.set({
256-
data,
257-
updatedAt: new Date(),
258-
})
259-
.where(and(eq(memory.key, id), eq(memory.workflowId, workflowId)))
247+
await db.delete(memory).where(and(eq(memory.key, id), eq(memory.workflowId, workflowId)))
260248

261249
// Fetch the updated memory
262250
const updatedMemories = await db

0 commit comments

Comments
 (0)