Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 140 lines (93 sloc) 3.025 kb
00400aa @winton README
authored
1 ActsAsArchive
2 =============
cc6c0c1 @winton First commit: partially working, partially tested
authored
3
00400aa @winton README
authored
4 Don't delete your records, move them to a different table.
90ffbf5 @winton README
authored
5
aab6c6b @winton Wrote specs for create_archive_indexes and migrate_from_acts_as_paranoid...
authored
6 Like <code>acts\_as\_paranoid</code>, but doesn't mess with your SQL queries.
cc6c0c1 @winton First commit: partially working, partially tested
authored
7
00400aa @winton README
authored
8 Install
9 -------
10
cc6c0c1 @winton First commit: partially working, partially tested
authored
11 <pre>
f16b286 @winton README, puts -> $stdout.puts
authored
12 gem install acts_as_archive
cc6c0c1 @winton First commit: partially working, partially tested
authored
13 </pre>
14
f16b286 @winton README, puts -> $stdout.puts
authored
15 ### Rails 2
16
17 #### config/environment.rb
9dc96bb @winton Fixing acts_as_archive binary (0.1.6)
authored
18
19 <pre>
20 config.gem 'acts_as_archive'
21 </pre>
22
f16b286 @winton README, puts -> $stdout.puts
authored
23 ### Rails 3
00400aa @winton README
authored
24
f16b286 @winton README, puts -> $stdout.puts
authored
25 #### Gemfile
cc6c0c1 @winton First commit: partially working, partially tested
authored
26
27 <pre>
f16b286 @winton README, puts -> $stdout.puts
authored
28 gem 'acts_as_archive'
cc6c0c1 @winton First commit: partially working, partially tested
authored
29 </pre>
30
f16b286 @winton README, puts -> $stdout.puts
authored
31 ### Sinatra
aab6c6b @winton Wrote specs for create_archive_indexes and migrate_from_acts_as_paranoid...
authored
32
f16b286 @winton README, puts -> $stdout.puts
authored
33 <pre>
34 require 'acts_as_archive'
35 </pre>
7424077 @winton Version 0.1.2: New rakefile, using bin/acts_as_archive to generate archi...
authored
36
f16b286 @winton README, puts -> $stdout.puts
authored
37 Add to models
38 -------------
39
40 Add <code>acts\_as\_archive</code> to your models:
81563fa @winton Adding migration instructions to README
authored
41
7424077 @winton Version 0.1.2: New rakefile, using bin/acts_as_archive to generate archi...
authored
42 <pre>
f16b286 @winton README, puts -> $stdout.puts
authored
43 class Article &lt; ActiveRecord::Base
44 acts_as_archive
45 end
7424077 @winton Version 0.1.2: New rakefile, using bin/acts_as_archive to generate archi...
authored
46 </pre>
47
f16b286 @winton README, puts -> $stdout.puts
authored
48 Migrate
49 -------
7424077 @winton Version 0.1.2: New rakefile, using bin/acts_as_archive to generate archi...
authored
50
f16b286 @winton README, puts -> $stdout.puts
authored
51 Next time you run <code>rake db:migrate</code>, your archive tables will be created automatically.
81563fa @winton Adding migration instructions to README
authored
52
00400aa @winton README
authored
53 That's it!
54 ----------
55
f16b286 @winton README, puts -> $stdout.puts
authored
56 Use <code>destroy</code>, <code>destroy\_all</code>, <code>delete</code>, and <code>delete_all</code> like you normally would.
aab6c6b @winton Wrote specs for create_archive_indexes and migrate_from_acts_as_paranoid...
authored
57
430f63e @winton README
authored
58 Records move into the archive table instead of being destroyed.
00400aa @winton README
authored
59
b0a72ff @winton README
authored
60 If any of your model's relationships have the <code>:dependent</code> option and also use <code>acts\_as\_archive</code>, those relationships will archive automatically.
61
87591b7 @winton Version 0.1.1
authored
62 What if my schema changes?
63 --------------------------
00400aa @winton README
authored
64
59022de @winton README
authored
65 New migrations are automatically applied to the archive table.
87591b7 @winton Version 0.1.1
authored
66
81563fa @winton Adding migration instructions to README
authored
67 No action is necessary on your part.
68
87591b7 @winton Version 0.1.1
authored
69 Query the archive
70 -----------------
71
72 Add <code>::Archive</code> to your ActiveRecord class:
00400aa @winton README
authored
73
74 <pre>
f16b286 @winton README, puts -> $stdout.puts
authored
75 Article::Archive.first
00400aa @winton README
authored
76 </pre>
77
f16b286 @winton README, puts -> $stdout.puts
authored
78 Delete records without archiving
79 --------------------------------
00400aa @winton README
authored
80
f16b286 @winton README, puts -> $stdout.puts
authored
81 Use any of the destroy methods, but add a bang (!):
00400aa @winton README
authored
82
87591b7 @winton Version 0.1.1
authored
83 <pre>
f16b286 @winton README, puts -> $stdout.puts
authored
84 Article::Archive.find(:first).destroy!
f29a2e9 @winton README
authored
85 Article.delete_all!([ "id in (?)", [ 1, 2, 3 ] ])
87591b7 @winton Version 0.1.1
authored
86 </pre>
00400aa @winton README
authored
87
f16b286 @winton README, puts -> $stdout.puts
authored
88 Restore from the archive
89 ------------------------
c2ab564 @winton README
authored
90
f16b286 @winton README, puts -> $stdout.puts
authored
91 Use any of the destroy/delete methods on the archived record to move it back to its original table:
430f63e @winton README
authored
92
93 <pre>
f16b286 @winton README, puts -> $stdout.puts
authored
94 Article::Archive.first.destroy
95 Article::Archive.delete_all([ "id in (?)", [ 1, 2, 3 ] ])
430f63e @winton README
authored
96 </pre>
97
f16b286 @winton README, puts -> $stdout.puts
authored
98 Magic columns
99 -------------
508fc5a @look add some docs for destroy! and delete_all!
look authored
100
f16b286 @winton README, puts -> $stdout.puts
authored
101 You will find an extra <code>deleted_at</code> datetime column on the archive table.
508fc5a @look add some docs for destroy! and delete_all!
look authored
102
f16b286 @winton README, puts -> $stdout.puts
authored
103 You may manually add a <code>restored_at</code> datetime column to the origin table if you wish to store restoration time as well.
508fc5a @look add some docs for destroy! and delete_all!
look authored
104
f16b286 @winton README, puts -> $stdout.puts
authored
105 Migrate from acts\_as\_paranoid
106 -------------------------------
508fc5a @look add some docs for destroy! and delete_all!
look authored
107
f16b286 @winton README, puts -> $stdout.puts
authored
108 Add this line to a migration, or run it via <code>script/console</code>:
508fc5a @look add some docs for destroy! and delete_all!
look authored
109
110 <pre>
f16b286 @winton README, puts -> $stdout.puts
authored
111 Article.migrate_from_acts_as_paranoid
112 </pre>
113
b0a72ff @winton README
authored
114 This copies all records with non-null <code>deleted_at</code> values to the archive.
115
116 Running specs
117 -------------
118
119 Contributions are always welcome.
120
121 <pre>
122 gem install acts_as_archive --development
123 spec/run
124 </pre>
125
126 <code>spec/run</code> essentially runs the following:
127
128 <pre>
129 ACTIVERECORD=3 spec -f n -c spec
130 ACTIVERECORD=2 spec -f n -c spec/acts_as_archive_spec.rb
131 RAILS=2 spec -f n -c spec/acts_as_archive_spec.rb
132 RAILS=3 spec -f n -c spec/acts_as_archive_spec.rb
133 SINATRA=1 spec -f n -c spec/acts_as_archive_spec.rb
134 </pre>
135
136 If you want to hack on the supporting gems ([mover](http://github.com/winton/mover) and [also_migrate](http://github.com/winton/also_migrate)), vendor them with the following command:
137
138 <pre>
139 externals un
140 </pre>
Something went wrong with that request. Please try again.