brendon / ranked-model

An acts_as_sortable/acts_as_list replacement built for Rails 4+
https://github.com/mixonic/ranked-model
MIT License
1.09k stars 134 forks source link

Migration acts_as_list => ranked_model #172

Closed sailerinteractive closed 3 years ago

sailerinteractive commented 3 years ago

Hi!

i'm about to migrate a project from acts_as_list to ranked_model and i'm trying to reuse the existing position integer column. I did some tests and it seems that this works really well without any additional migrations since the column values are automatically spaced out when the first position changes happen. Do i overlook something here or is it really that simple? If it works simply like that it might be worth mentioning that in the docs.

Florian

brendon commented 3 years ago

Hi @sailerinteractive, that should work fine, but it will rebalance almost immediately if you resort the items as there will be a collision. One thing to be aware of is two items having the same position value as that can easily happen with acts_as_list due to overlapping requests. Might be better to either verify that isn't the case, or migrate across by manually saving each item in the list in order with the position set to last (which is the default anyway from memory).

Hope that helps :D