Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hi there #19

Open
wants to merge 1 commit into from

8 participants

@DCarper

Looks like a great gem, I was a little hazy in getting this all set up though.

It would be more clear if the readme highlighted the need to call #acts_as_archive on the respective class even though it might be obvious to some. Also highlighting the fact that migrations run without feedback would be good too.

If this differs from your experience then I apologize, it's entirely possible there is something wonky with my system.

Once again nice gem dudes

Dan

@winton
Owner

Hey Dan, thanks for the kind words.

It is no longer necessary to declare acts_as_archive on the class. Was the YAML file alone not working for you?

I agree on the other points.

@DCarper

I'm pretty sure I followed the instructions exactly but maybe I missed something. Things only started working after I added the macro method in, but now I can remove it and tests still pass..

So either the migrations still depend on it in some way or I was doing something wrong.. I can test it more thoroughly later tonight hopefully

@elmatou
Collaborator

Hi folks,
I am experiencing the same issue.
Coming from the previous version of acts_as_archive, I refactor a bit my app to comply with the new way of acts_as_archive.
I have got a nice yml file, removing acts_as_archive statement in models
I even removed the tables in the DB in order to recreate them.
but nothing append in migration...

rake db:migrate --trace
(in xxxxxxxxxxxxxxxxxxxxxxxxxx)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment 
** Execute db:schema:dump

No error but No table are created....

EDIT :
In rails console too I didn't have anything..

>> Role::Archive
Role::Archive
NameError: uninitialized constant Role::Archive

I am stuck in Ruby1.8.7 & Rails 2.3.10 & acts_as_archive 0.4.0

@phlegx

Same problem: no archive tables created! Ruby 1.9.2, Rails3.0.3

Whit "acts_as_archive" in the model class all works fine!

@elmatou
Collaborator

Fixed (even if I have the devise issue too)
Rails loaded the previous version of acts_as_archive, everything is ok after a little cleaning in the gems.

@larryh

Hi,
Same goes for me. (I'm using Ruby 1.9.2 and Rails 3.0.4)

I created config/acts_as_archive.yml with the following contents:

Politician::Person:
  - class: Politician::Person::Archive
    table: archive_politician_persons

When I ran db:migrate nothing happened. When I added "acts_as_archive" in my model and then ran db:migrate the table was created, but it was called "archived_politician_persons" as opposed to what was specified in the yml file (i.e. "archive" without the 'd')

This small problem aside, I am psyched to use your gem. Thanks for providing it!

@pboling

I have this problem too. Rails 2.3.11, Ruby 1.8.7, and when I run rake db:migrate I get:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
* When you upgrade to Ruby 1.9 fastercsv gem will not be a dependecy anymore
* When you upgrade to Ruby 1.9 fastercsv gem will not be a dependecy anymore
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment 
** Execute db:schema:dump

No migrations are created. As an interesting aside I also was forced to comment out all my class macro methods from other gems/plugins (e.g. attachment_fu's has_attachment among others) in order to get rake db:migrate to run at all (not usually the case).

I am not sure where to go from here.

Edit: I see now that the tables were created automatically. So only problem I had was a confusion over thinking it hadn't worked when it has, and needing to comment a bunch of class macros from other gems.

@pboling

The tables were created fine in development mode, but in production only one of the eight tables I have set as acts_as_archive had the archive table created. It is very strange. I don't seem to be able to get the migrations to run of the other tables to run. All are defined in the model files. The gem doesn't work at all with the YAML configuration file, so I had to delete it.

@pboling

Using as a plugin instead of a gem and things now work. acts_as_archive does not seem to work as a gem in production (worked in development though).

@elmatou
Collaborator

Migrations works fine for me, when used as a gem ! using Rails 2.3.11, Ruby 1.8.7
But there are some other issues (see issue tracker)

@nguyenannguyen

Hi Winton and elmatou,
First, thanks for the gem. It is exactly the implementation for soft-delete approach that I am looking for. I am having problem installing it though. I can't install it as a gem, so followed pboling's comment to install it as a plugin, then add acts_as_archive to the model, create yml file in config/, then run bundle install. It ran successfully but the table was not created. In my console:

ruby-1.9.2-p180 :001 > Ticket::Archive

=> Ticket::Archive(Table doesn't exist)

I am using Rails 3.0.10 on Ruby 1.9.2. I wonder how I can fix this.

@elmatou
Collaborator

Hi,
1 - The tables are created while migrating the db. Did you run rake db:migrate after the bundle install (if you use it as a gem) and setup ?
2 - If so try to check if the plugin/gem is currently loaded with the app (Check if ActsAsArchive class is declared), and load it manualy if not.
3 - Then check with rails 3.0.9, there is a new feature in 3.1.0 allowing to migrate the db with the migration embeded in gems/engines, it could have break ActsAsArchive.

See you.

@nguyenannguyen

Hi elmatou,

Thanks a lot for your answer. I run gem list and saw acts_as_archive (0.4.0) there. I did create yml file in config and run rake db:migrate. It ran successfully but table is not created.

I am stuck with 3.0.10 because one of the key gems I installed required it. If I create archive table manually (with all columns plus magic column), would the acts_as_archive work? Otherwise, could you please advice on how I can hack it to reconcile with 3.0.10?

@elmatou
Collaborator

Hi,

gem list show if the gem is present in the system. it is not related to your (rails) application.

My point is to check if the plugin or gem is loaded with the app when starting the server (or migration).

ruby-1.9.2-p180 :001 > ActsAsArchive
=> ActsAsArchive

In order to correctly migrate the database, the rake task come in the following process :

  • load the rails app, while loading, acts_as_archive (or more accuratly also_migrate do it) set a hook in next step. (writting this I think you should check if acts_as_archive dependencies are vendored along with the plugin).
  • migrations are ran, and the proper table are created. If acts_as_archive was loaded with the app, it migrate also the archive tables.

For me there is only tow possible cause, either act_as_archive is not loaded along with the app, either the yaml file is not at the right place.

bye

@nguyenannguyen

Hi elmatou,

Thanks a lot for your help. I have been trying to install it for 2 days now. I just reverse my installation and have a clean install using your fork to avoid conflict with Devise:

kidville:rails plugin install git://github.com/elmatou/acts_as_archive.git --force
kidville:rake db:migrate

rake aborted!
also_migrate is not part of the bundle. Add it to Gemfile.

I add gem 'also_migrate' to Gemfile and run

kidville:gem install also_migrate

Successfully installed also_migrate-0.3.5

kidville:rake db:migrate

rake aborted!
mover is not part of the bundle. Add it to Gemfile.

I added gem 'mover' to Gemfile and run plugin install again. Now install is successful.

I created acts_as_archive.yml in config, specify acts_as_archive in the model and run rake db:migrate. It ran through silently but did not create table.

It seems to me that acts_as_archive doesn't load this time:
ruby-1.9.2-p180 :033 > ActsAsArchive

NameError: uninitialized constant ActsAsArchive

Since I already asked a lot, I spend the whole day trying to reinstall and figure out. It seems that I need some guidance from you again to figure out dependencies in order to get acts_as_archive load correctly.

Thanks again.

@nguyenannguyen

P/S: when I add to environment.rb:

require "acts_as_archive/adapters/rails#{Rails.version[0..0]}" if defined?(Rails)
require "acts_as_archive/adapters/sinatra" if defined?(Sinatra)

and run rake db:migrate, I got the following error message:

rake aborted!
no such file to load -- acts_as_archive/adapters/rails3

@nguyenannguyen

Hi elmatou,

After restart my Terminal, I got back to the same place where I started my question yesterday:

ruby-1.9.2-p180 :004 > ActsAsArchive
=> ActsAsArchive

ruby-1.9.2-p180 :005 > Ticket::Archive
=> Ticket::Archive(Table doesn't exist)

This means that the gem does get loaded to my app, but somehow the migration fails. (I am sure I put the yml file in config folder). Could you let me know your diagnose?

@nguyenannguyen

A quick follow-up with elmatou:
When I create archive table manually (same migration with original model but add deleted_at column of datetime type), I can call:
Model::Archive.last

nil

@nguyenannguyen

However, when I delete rows from main table, there's no record created in archived_model.

@elmatou
Collaborator

Ok, I'm not getting what's wrong with your setup.

I'm gonna describe mine (Rails 2.3.11).
1 - Install as a gem (it is really better to use it as a gem), why are you installing it as a plugin ?

gem 'acts_as_archive', :git => "git://github.com/elmatou/acts_as_archive.git", :branch => "ako"

Here I use a branch dedicated to one of my project, it geather polymorphic association fix and manual loading of the library

2 - manual load in environment.rb (after Rails::Initializer.run block)

require "acts_as_archive/adapters/rails#{Rails.version[0..0]}" if defined?(Rails)

no such file to load -- acts_as_archive/adapters/rails3 means that acts_as_archive is not located at the proper place (check if the vendor path is in the load path, or use it as a gem)

3 - create yml file : config/acts_as_archive.yml

Profil:
  - class: Profil::Archive
    table: archived_profils

4 - Add nothing in the model OR you can try to setup the archive directly in the model (and let acts_as_archive.yml empty)

class Profil < ActiveRecord
  acts_as_archive :class => Profil::Archive, :table => archived_profils
end

5 - bundle install & rake db:migrate (rake tasks accept --trace option for a better verbosity of exceptions)

6 - load the app (avoid the rails console because it load things differently) and check if some acts_as_archive methods are present :

Profil.respond_to? :migrate_from_acts_as_paranoid
Profil.respond_to? :delete_all!

Now, if it doesn't work, I don't know what to say...

It is sad this gem is not maintaned anymore, as it is IMHO a very good soft deletion strategy (Not very suitable for heavy app, but much more easy to use as a developper).

check here for other implementation :
http://www.ruby-toolbox.com/categories/activerecord_soft_delete.html

Anyhow acts_as_paranoid work also very well.

Good luck with your issue

@nguyenannguyen

Hi elmatou,

It's very kind of you to give me such a detailed advice! I tried to install your version as a gem but github does not support gem anymore (although winton's version is still available for gem install as legacy), so installation was tricky.

I really appreciate your help and acts_as_archive approach, but I guess I should use permanent_records for now. I'll revisit this once my site gets big enough. :-)

Thanks again.

@nathanbertram

+1 for this; thanks for the note Dan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 1, 2011
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 2 deletions.
  1. +10 −2 README.md
View
12 README.md
@@ -51,10 +51,18 @@ Article:
It is expected that neither the archive class or archive table exist yet. <code>ActsAsArchive</code> will create these automatically.
+Override ActiveRecord
+----------------
+<pre>
+class Article &lt; ActiveRecord::Base
+ acts_as_archive
+end
+</pre>
+
Migrate
-------
-Run <code>rake db:migrate</code>. Your archive table is created automatically.
+Run <code>rake db:migrate</code>. Your archive table is created automatically. (There will be no output -- this is normal)
That's it!
----------
@@ -127,4 +135,4 @@ This copies all records with non-null <code>deleted_at</code> values to the arch
Running specs
-------------
-There is a [wiki entry](https://github.com/winton/acts_as_archive/wiki/Running-Specs) that describes the development setup in-depth.
+There is a [wiki entry](https://github.com/winton/acts_as_archive/wiki/Running-Specs) that describes the development setup in-depth.
Something went wrong with that request. Please try again.