1- import { and , eq , isNull } from 'drizzle-orm'
1+ import { and , eq } from 'drizzle-orm'
22import { type NextRequest , NextResponse } from 'next/server'
33import { createLogger } from '@/lib/logs/console-logger'
44import { 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