Soft Delete

Record preservation using deletedAt timestamps instead of hard deletion, with Prisma client extensions, cascade operations, restore functionality, and cleanup jobs.

What's Included#

  • Schema setup with deletedAt column and index
  • Prisma client extension that intercepts delete/findMany to use soft delete automatically
  • Manual soft delete, restore, and hard delete helper functions
  • Query helpers for active, deleted, and all records
  • Cascade soft delete for related records in a transaction
  • Prisma middleware approach for model-wide soft delete enforcement
  • Restore with related records based on matching deletion timestamp
  • Admin trash view UI with restore and permanent delete options
  • Scheduled cleanup job for permanently removing old soft-deleted records

Usage#

Via CLI#

Loading code block...

Via AI Assistant#

Ask your AI assistant:

  • "Use the soft delete pattern from Bootspring"
  • "Apply the Bootspring soft delete pattern to my project"

Key Considerations#

  • Add a database index on the deletedAt column to maintain query performance
  • Use transactions when cascading soft deletes across related tables
  • Set retention policies to periodically hard delete records past the retention window
  • Provide an admin UI for restoring accidentally deleted records
  • Make the soft delete behavior explicit in documentation so developers understand the filtering