Closed bvkimball closed 1 year ago
@bvkimball Actually using access policy we could already achieve that in ZenStack:
model Post {
...
deleted Boolean @default(false) @omit
@@deny('read', deleted)
...
}
There is a blog post about it:
awesome... sorry i missed this, I would still need to implement a middleware or extension as described to "override" the default delete*
actions right?
No. All you need to do is to define the policy in the schema as in the example above. ZenStack will take care of the rest. 😄
Is your feature request related to a problem? Please describe. Currently, Prisma Schema Language doesn't provide a built-in way to handle soft deletes for objects. As a result, developers have to manually manage soft deleted objects in their applications. This can be cumbersome, especially when dealing with larger projects.
Describe the solution you'd like I propose adding an attribute to Zenstack that will allow users to easily implement soft deletes for objects. This could be done by introducing a new
@deletedAt
attribute, which can be applied to models in the schema definition. The attribute would automatically add the necessary fields for soft deletion, such as a deletedAt timestamp field, and would handle the relevant queries to filter out soft deleted records.Example usage:
Describe alternatives you've considered An alternative is to manually implement soft deletes in the application logic by adding a deletedAt field and filtering out soft deleted records in every query. However, this can be error-prone and time-consuming, as developers need to ensure that they handle soft deletes correctly in all parts of their application.
Additional context Integrating the
@deletedAt
attribute into the Zenstack would provide a more streamlined and efficient way for developers to implement soft deletes in their applications. It would also promote best practices for handling soft deleted records and reduce the chances of bugs related to improper handling of soft deletes.The prisma client should filter out deleted records for all standard actions ie
find*
. Open question would be how to find "deleted" Objects, this could be a new function forfindDeleted
or an extra option in thefind*
methods forincludeDeleted: true
.