winton / acts_as_archive

Don't delete your records, move them to a different table
MIT License
372 stars 87 forks source link

Indexes on more than 1 column will fail #6

Closed gravis closed 14 years ago

gravis commented 14 years ago

Hi,

I've noticed indexes for "polymorphic" columns are failing :

acts_as_archive :indexes => [ user_id, [:model_id, :model_type]]

I should have an index on user_id and model_id+model_type, instead I get an error : ActiveRecord::StatementInvalid: PGError: ERROR: column "model_idmodel_type" does not exist

winton commented 14 years ago

Give this a try:

acts_as_archive :indexes => [ :user_id, :model_id, :model_type ]
gravis commented 14 years ago

I get (of course) : ... "index_archived_users_on_model_id" btree (model_id) "index_archived_users_on_model_type" btree (model_type)

not an index on (model_id, model_type). It's really not the same :(

winton commented 14 years ago

Ah, I see, unfortunately that's not currently supported. Looks like you'll have to add them manually via migration. If you want to add some code I would be happy to pull your changes :).

gravis commented 14 years ago

Ok Winton, I will, but I need a few days to submit a patch (/pull request). Maybe this week-end ! I'll keep this ticket updated. Thanks

gravis commented 14 years ago

sorry, but why is this ticket closed ?

winton commented 14 years ago

Sorry, I closed it upon posting my comment, sort of as a "wontfix". Please feel free to continue updating it and I will pull your changes as soon as you're ready.

gravis commented 14 years ago

Thanks :) We found another bug, I'll file a ticket and try to fix it asap

gravis commented 14 years ago
acts_as_archive :indexes => [ user_id, [:model_id, :model_type]] 

is now supported on pgsql : http://github.com/gravis/acts_as_archive/commit/1d4fc6f05261d348f49f2d4a32642d7e274896b4 Anyway, I'm not a MySQL expert, it will certainly break something (I don't have mysql to test), but I'm sure you will be able to fix them easily ;)

Thanks

gravis commented 14 years ago

MySQL was a bit of pain to support, but here it is : http://github.com/gravis/acts_as_archive/commit/b93e035dcb5e3a4ea07ebfd87937e8001eb8e41b