Don't delete your records, move them to a different table.
acts_as_paranoid, but doesn't mess with your SQL queries.
sudo gem install acts_as_archive
acts_as_archive to your models:
Run acts_as_archivecd your_rails_app acts_as_archive Article
Run this command every time you add
acts_as_archiveto a new model.
This command creates your archive tables (
archived_articlesas per the example).
Archive tables mirror your table's structure, but with an additional
delete_alllike you normally would.
Records move into the archive table instead of being destroyed.
What if my schema changes?
New migrations are automatically applied to the archive table.
Query the archive
::Archiveto your ActiveRecord class:Article::Archive.find(:first)
Restore from the archive
restore_allto copy archived records back to your table:Article.restore_all([ 'id = ?', 1 ])
Auto-migrate from acts_as_paranoid
If you previously used
acts_as_archivecommand will automatically move your deleted records to the archive table (see Run acts_as_archive).
deleted_atvalues are preserved.
Add indexes to the archive table
To keep insertions fast, there are no indexes on your archive table by default.
If you are querying your archive a lot, you will want to add indexes:class Article [ :id, :created_at, :deleted_at ] end
acts_as_archivecommand upon adding new indexes (see Run acts_as_archive).