Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Don't delete your records, move them to a different table
Ruby
tree: 36fd1c14a2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
rails
spec
.gitignore
CHANGELOG.markdown
MIT-LICENSE
README.markdown
Rakefile
acts_as_archive.gemspec
init.rb

README.markdown

ActsAsArchive

Don't delete your records, move them to a different table.

Like acts_as_paranoid, but doesn't change all your SQL queries.

Install

script/plugin:

script/plugin install git://github.com/winton/acts_as_archive.git

rubygems:

# terminal
sudo gem install winton-acts_as_archive

# environment.rb
config.gem "winton-acts_as_archive", :lib => "acts_as_archive", :source => "http://gems.github.com"

Models

Add acts_as_archive to your models:

class Article < ActiveRecord::Base
  acts_as_archive
end

That's it!

Next time your Rails instance boots up, the plugin replicates your table's structure into archived_articles (as per the example), with an additional deleted_at column.

Use destroy, delete, and delete_all like you normally would. Records are copied into the archive table before being destroyed.

What if my schema changes?

Any new migrations on your acts_as_archive table are automatically applied to the archive table.

Query the archive

Add ::Archive to your ActiveRecord class:

Article::Archive.find(:first)

Restore from the archive

Use restore_all to copy archived records back to your table:

Article.restore_all([ 'id = ?', 1 ])

Auto-migrate from acts_as_paranoid

If a deleted_at column is present in your table, the plugin will attempt to move deleted records to the archive table. The deleted_at value is preserved.

Production

Any time you add a new acts_as_archive method call, please run script/console on your production copy before it goes live.

Something went wrong with that request. Please try again.