A Rails gem for soft-deleting records by setting a deleted_at timestamp instead of removing them from the database.
Paranoia is a Ruby gem for Rails applications that implements soft deletion for ActiveRecord models. It allows records to be marked as deleted by setting a `deleted_at` timestamp instead of being permanently removed from the database, preserving data for recovery or auditing purposes. It provides scopes and methods to query, restore, or permanently destroy records as needed.
Rails developers who need to implement soft deletion in their applications, particularly those migrating from older `acts_as_paranoid` implementations or building systems where data retention and recovery are important.
Paranoia offers a straightforward, minimalistic approach to soft deletion with full compatibility for Rails 5 through 7, including support for associations, callbacks, and customizable columns. It is maintained for bug fixes and Rails version updates, though new projects may consider alternatives like `discard` for more predictable behavior.
acts_as_paranoid for Rails 5, 6 and 7
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Overrides ActiveRecord's destroy method to set a deleted_at timestamp, making it straightforward to implement soft deletion with minimal code changes, as shown in the basic usage examples.
Automatically handles dependent associations by soft-deleting them if they use acts_as_paranoid, ensuring data integrity without manual intervention, detailed in the 'Destroying through association callbacks' section.
Provides scopes like with_deleted, only_deleted, and without_deleted for granular access to records, allowing easy inclusion or exclusion of soft-deleted data in queries.
Offers restore methods with recursive options and supports destroy, real_destroy, and restore callbacks, enabling seamless integration with external systems like search engines for audit trails.
Overrides core ActiveRecord methods like delete and destroy, which the README admits leads to 'surprising behaviour' and is not recommended for new projects, potentially causing bugs in unfamiliar codebases.
The project is in maintenance mode, only accepting bug fixes and Rails version updates with no new features, limiting its evolution compared to alternatives like discard.
Requires adapting database indexes to include where clauses for deleted_at to maintain performance, adding overhead and complexity that isn't needed with hard deletion or some alternatives.