[Feature Request] A real soft-delete feature
Background
Current pattern: https://zenstack.dev/blog/soft-delete
But it has some limitations:
- You can't call the regular
deletemethod onDeletereferential actions don't work
Proposed Solution
The thought is to make it as simple as:
model Foo {
...
deletedAt DateTime? @softDelete
}
And the enhance() API can have an option to opt-in for it:
const db = enhance(prisma, { user: ..., softDelete: true });
When enabled, the enhanced client has additional behavior:
deleteanddeleteMany(including nested ones) become soft deleteonDelete: Cascadepropagate soft-delete to related entities- Read APIs (findXXX, count, aggregate, groupBy) automatically exclude soft-deleted entities
More Context
Context from chat with ikishan on discord:
const db = enhance(prisma, { user: ..., softDelete: true });
It would be specifically cool if we can have softDelete without enhance/an alternative function that doesn't use the authorization layer
I have a global export of prisma and I use that in my webhooks and cron jobs. I would love if they could also have soft deletes, but there is no "user" in those contexts so enchance wouldn't make sense. Would also be nice if they can respect the validations as well.
const db = enhance(prisma, { user: ..., softDelete: true });
It would be specifically cool if we can have softDelete without enhance/an alternative function that doesn't use the authorization layer
I have a global export of
prismaand I use that in my webhooks and cron jobs. I would love if they could also have soft deletes, but there is no "user" in those contexts soenchancewouldn't make sense. Would also be nice if they can respect the validations as well.
With the new unified enhance API in V2, it's probably going to look like:
const dbSoftDelete = enhance(prisma, undefined, { kinds: ['soft-delete'] });
Data validation is also part of access control today. It'll be a separate task to spin it out 😄