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:
2026-04-21 16:18:25 -04:00
parent 0cf4612106
commit da938c1fcf
2 changed files with 2 additions and 1 deletions

View File

@@ -103,7 +103,7 @@ model BudgetRule {
model CsvUpload {
id String @id @default(cuid())
accountId String
account Account @relation(fields: [accountId], references: [id])
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
fileName String
rowCount Int
importedCount Int

View File

@@ -58,6 +58,7 @@ export async function DELETE(_req: Request, { params }: Params) {
})
if (!existing) return NextResponse.json({ error: 'Not found' }, { status: 404 })
await prisma.csvUpload.deleteMany({ where: { accountId: id } })
await prisma.account.delete({ where: { id } })
return new NextResponse(null, { status: 204 })
}