Fix account delete blocked by CsvUpload FK constraint
Add onDelete: Cascade to CsvUpload.accountId so deleting an account cascades to its upload records. Also explicitly delete uploads before the account in the API route so existing deployed DBs without the constraint don't error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -103,7 +103,7 @@ model BudgetRule {
|
|||||||
model CsvUpload {
|
model CsvUpload {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
accountId String
|
accountId String
|
||||||
account Account @relation(fields: [accountId], references: [id])
|
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
|
||||||
fileName String
|
fileName String
|
||||||
rowCount Int
|
rowCount Int
|
||||||
importedCount Int
|
importedCount Int
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export async function DELETE(_req: Request, { params }: Params) {
|
|||||||
})
|
})
|
||||||
if (!existing) return NextResponse.json({ error: 'Not found' }, { status: 404 })
|
if (!existing) return NextResponse.json({ error: 'Not found' }, { status: 404 })
|
||||||
|
|
||||||
|
await prisma.csvUpload.deleteMany({ where: { accountId: id } })
|
||||||
await prisma.account.delete({ where: { id } })
|
await prisma.account.delete({ where: { id } })
|
||||||
return new NextResponse(null, { status: 204 })
|
return new NextResponse(null, { status: 204 })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user