Ad

paranoia: Soft Deletes for Rails

Paranoia implements soft deletes for Rails models, providing a simple mechanism to hide records instead of permanently deleting them.
Screenshot of rubysherpas/paranoia homepage

Paranoia is a Ruby gem for Rails that implements soft deletes, a pattern where records are not physically deleted from the database but instead marked as inactive. When a record is 'destroyed', its deleted_at column is set to the current timestamp, and database queries are modified to exclude these soft-deleted records. This approach preserves data integrity and allows for data recovery. It aims to replicate the functionality of acts_as_paranoid with a significantly reduced codebase.

Paranoia offers a lightweight alternative to more complex soft-deletion solutions. It supports flexible column management for tracking deletion timestamps. Its scope management features handle soft-deleted records efficiently, allowing for easy retrieval of active or deleted data. The gem provides clear mechanisms for data restoration, offering both simple and recursive options.

  • Core Functionality: Implements soft deletes by setting a deleted_at timestamp on records. Supports easy lookup of deleted and active records.
  • Rails Compatibility: Designed for Rails 3, 4, 5, and 6, automatically adapting its behavior. Provides migration generation for easy setup.
  • Data Restoration: Includes methods to restore soft-deleted records in individual or bulk operations, with optional recursive restoration of associated records.
  • Flexible Configuration: Allows specifying a custom column for tracking deletions instead of the default deleted_at column. Offers an option to skip the default scope.
  • Unique Constraints: Provides mechanisms for performing unique constraints on the deleted_at column. Optional methods to incorporate a boolean active column for uniqueness.
  • Association Handling: Manages soft-deleted associations and provides methods for querying associated records including those that are soft deleted.
  • Developer Experience: Includes helpful methods and concerns, along with a number of performance enhancements and indexes.

Paranoia has been in development for a considerable time, with ongoing maintenance and bug fixes. It demonstrates active use and a strong community presence. While new feature development is paused, the gem remains reliable for managing soft deletions in Rails applications. The project's usage statistics and regular updates indicate a stable and well-supported solution.

Paranoia is valuable for Rails developers who require a straightforward and efficient way to implement soft deletes. It's especially useful when data retention is important or when accidental data deletion needs to be easily reversed. By providing a clean and well-documented solution, Paranoia helps developers maintain data integrity and provides a robust approach to managing data lifecycles.

Languages:
Summarize:
Share:
Stars
2,916
Forks
524
Issues
103
Created
15 years ago
Commit
10 months ago
License
OTHER
Archived
No
Updated 1 hour ago

Similar Repositories