Skip to content

[Feature Request] A real soft-delete feature #520

@ymc9

Description

@ymc9

Background

Current pattern: https://zenstack.dev/blog/soft-delete

But it has some limitations:

  • You can't call the regular delete method
  • onDelete referential 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:

  1. delete and deleteMany (including nested ones) become soft delete
  2. onDelete: Cascade propagate soft-delete to related entities
  3. Read APIs (findXXX, count, aggregate, groupBy) automatically exclude soft-deleted entities

More Context

Context from chat with ikishan on discord:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions