Open ymc9 opened 1 year ago
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
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 soenchance
wouldn'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 😄
Someone seems to have implemented a resursive soft delete extension in Prisma. https://github.com/prisma/prisma/issues/3398#issuecomment-2310457180 What do you think?
Background
Current pattern: https://zenstack.dev/blog/soft-delete
But it has some limitations:
delete
methodonDelete
referential actions don't workProposed Solution
The thought is to make it as simple as:
And the
enhance()
API can have an option to opt-in for it:When enabled, the enhanced client has additional behavior:
delete
anddeleteMany
(including nested ones) become soft deleteonDelete: Cascade
propagate soft-delete to related entitiesMore Context
Context from chat with ikishan on discord: