bookshelf-paranoia is a plugin for Bookshelf.js that provides a transparent soft-delete mechanism for database records. Instead of permanently removing rows when `destroy` is called on a model, it sets a `deleted_at` timestamp on the record, effectively marking it as deleted without losing the data. This allows for easier data recovery and maintains historical data integrity within the database. The package is currently at version 0.13.1. A crucial aspect of this package is its "unmaintained" status, as explicitly stated by the author, who only dedicates minimal time to small fixes at a slow pace. This implies an uncertain release cadence and potential for slow resolution of issues. Its primary differentiator lies in seamlessly integrating soft-delete logic directly into Bookshelf models and queries, automatically excluding soft-deleted records from standard `fetch` operations and eager loadings, while offering overrides for hard deletion or retrieval of deleted records. This transparent approach minimizes changes required in application logic when implementing soft deletes.
npm install bookshelf-paranoiaVerified import paths — ran on the pinned version, not inferred.
Demonstrates the installation, model configuration, and basic usage of `bookshelf-paranoia` including soft deletion, fetching deleted records, and performing hard deletes.
Evaluate the project's long-term viability for your application. Consider contributing to a fork or migrating to an actively maintained solution for soft deletes in Bookshelf.js or your ORM of choice.
Implement partial (or 'scoped') unique indexes at the database level where the uniqueness constraint only applies to records where `deleted_at` IS NULL. Alternatively, modify your application logic to check for soft-deleted conflicts before insertion, or consider unique constraints that include the `deleted_at` field.
If this behavior is undesirable, you can disable event emission for soft deletes when configuring the plugin: `bookshelf.plugin(require('bookshelf-paranoia'), { events: false })` or disable specific events: `bookshelf.plugin(require('bookshelf-paranoia'), { events: { destroying: false } })`. Adjust your event listeners to account for soft deletions or only trigger on `hardDelete: true` scenarios.Modify your database schema to use partial unique indexes. For PostgreSQL, `CREATE UNIQUE INDEX users_email_unique ON users (email) WHERE deleted_at IS NULL;`. For MySQL, this often requires a more complex multi-column unique key including `deleted_at` or application-level checks. Ensure your `deleted_at` column allows NULL values and defaults to NULL.