• Stars
    star
    372
  • Rank 114,858 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated almost 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

ActsAsArchive

This project is no longer maintained. If you would like to become the new owner, please email Winton Welsh.

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

Like acts_as_paranoid, but doesn't mess with your SQL queries.

Install

gem install acts_as_archive

Rails 2

config/environment.rb

config.gem 'acts_as_archive'

Rails 3

Gemfile

gem 'acts_as_archive'

Sinatra

require 'acts_as_archive'

class Application < Sinatra::Base
  include ActsAsArchive::Adapters::Sinatra
end

config/acts_as_archive.yml

Create config/acts_as_archive.yml to define the archive class and archive table for each of your models:

Article:
  - class: Article::Archive
    table: archived_articles

It is expected that neither the archive class or archive table exist yet. ActsAsArchive will create these automatically.

Migrate

Run rake db:migrate. Your archive table is created automatically.

That's it!

Use destroy, destroy_all, delete, and delete_all like you normally would.

Records move into the archive table instead of being destroyed.

Automatically archive relationships

If your model's relationship has the :dependent option, and the relationship also uses acts_as_archive, that relationship will archive automatically.

What if my schema changes?

New migrations are automatically applied to the archive table.

No action is necessary on your part.

Query the archive

Use the archive class you specified in the configuration:

Article::Archive.first

Delete records without archiving

Use any of the destroy methods, but add a bang (!):

Article::Archive.first.destroy!
Article.delete_all!([ "id in (?)", [ 1, 2, 3 ] ])

Restore from the archive

Use any of the destroy/delete methods on the archived record to move it back to its original table:

Article::Archive.first.destroy
Article::Archive.delete_all([ "id in (?)", [ 1, 2, 3 ] ])

Any relationships that were automatically archived will be restored as well.

Magic columns

You will find an extra deleted_at datetime column on the archive table.

You may manually add a restored_at datetime column to the origin table if you wish to store restoration time as well.

Migrate from acts_as_paranoid

Add this line to a migration, or run it via script/console:

Article.migrate_from_acts_as_paranoid

This copies all records with non-null deleted_at values to the archive.

Running specs

There is a wiki entry that describes the development setup in-depth.

More Repositories

1

stasis

Static sites made powerful
Ruby
679
star
2

smart_asset

Smart asset packaging for Rails, Sinatra, and Stasis
Ruby
82
star
3

lilypad

Airbrake notifier for rack-based frameworks
Ruby
57
star
4

ubistrano

Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano and EC2
Ruby
32
star
5

gulp-docker

CoffeeScript
27
star
6

externals

Quickly freeze and unfreeze external git dependencies
Ruby
25
star
7

sum

A budgeting app built on Sinatra (view it at sumapp.com)
JavaScript
24
star
8

captcha

A Google-style captcha for enterprise Rails apps
Ruby
22
star
9

also_migrate

Migrate multiple tables with similar schema at once
Ruby
22
star
10

node-template

Node.js package template
JavaScript
17
star
11

rbackup

Backup your stuff with Ruby and Rsync
Ruby
13
star
12

gitcycle

Development cycle automation
Ruby
13
star
13

mover

Move ActiveRecord records across tables like it ain't no thang
Ruby
11
star
14

admin

An instant Admin for your Rails application
JavaScript
8
star
15

acts_as_relationable

Quick and easy habtm :through relationships in Rails
Ruby
7
star
16

cookbook

Turns a fresh Debian server into an autonomous Nginx/Rails/PHP stack using purely Capistrano
Ruby
6
star
17

nginx-accelerator

Drop-in page caching using nginx, lua, and memcached
Ruby
6
star
18

puggernaut

Simple server push implementation using eventmachine and long polling
JavaScript
5
star
19

gem_template

Gem template for new Ruby projects
Ruby
5
star
20

active_wrapper

Wraps ActiveRecord and Logger for use in non-Rails environments
Ruby
5
star
21

background_cache

Bust caches before your users do
Ruby
5
star
22

a_b_server

A/B test data aggregator as a Sinatra web service
Ruby
4
star
23

rails_widget

Group your client-side assets into distributable "widgets"
Ruby
4
star
24

timed_config

Load a YAML config every X minutes
Ruby
4
star
25

redis_parse

Reads huge amounts of pipe-delimited data from Redis, filters it, and returns counts by occurence
C
4
star
26

stutools

Addons to the MooTools javascript library
JavaScript
4
star
27

element

Element widget
3
star
28

dialog

Dialog widget
3
star
29

app_helpers

Sets up a fresh Rails project and adds useful helpers
JavaScript
3
star
30

superjail

Ruby jailkit wrapper
3
star
31

lightbox

Lightbox widget
JavaScript
3
star
32

require

Manage your project's dependencies with a pretty DSL
Ruby
3
star
33

widgets

A collection of my commonly used widgets
JavaScript
3
star
34

cap_reserve

Uses a maitre_d server to reserve time on deploy environments
Ruby
2
star
35

coffee-migrate

Abstract migration framework for node (in coffeescript)
CoffeeScript
2
star
36

stencil

Project template manager
Ruby
2
star
37

json_schema_spec

Generate fixtures from JSON schemas
Ruby
2
star
38

change

What files changed since last time?
Ruby
2
star
39

studicious_coming_soon

I lied :(
Ruby
2
star
40

framework_fixture

Dynamically generate Rails and Sinatra apps to be tested by Rack::Test
Ruby
2
star
41

auto-terminal

Use Auto from the command line
Ruby
1
star
42

maitre_d

A reservation API for deploy environments.
JavaScript
1
star
43

facehugger

Wraps the Facebook Javascript SDK in a warm, loving, jQuery-ish embrace
JavaScript
1
star
44

periodic_counter

Maintains period fields on any counter column in your database
Ruby
1
star
45

stasis_template

Stasis project template
JavaScript
1
star
46

stasis-server

Redis-backed queue for Stasis render jobs
Ruby
1
star
47

a_b

Talk to a_b_server from your Rails or Sinatra app
Ruby
1
star
48

node-aws-coreos

Helper classes to run a CoreOS stack on AWS and your local machine
CoffeeScript
1
star
49

secret_key

Provides an accessor for a secret key stored in tmp
Ruby
1
star
50

a_b_front_end

Front end for a_b
JavaScript
1
star
51

lighthouse_db

Lighthouse API -> Database
Ruby
1
star
52

bank-run

Basic statistics about your bank/credit transactions
CoffeeScript
1
star
53

docker-remote

Wrapper for the Docker remote API and CLI
CoffeeScript
1
star
54

with_pid

The simple way to create and monitor a Ruby daemon
Ruby
1
star
55

auto

Automate everything!
Ruby
1
star
56

execache

Run commands in parallel and cache the output, controlled by Redis
Ruby
1
star
57

auto-question

Ask questions from Auto
Ruby
1
star