has-friendship / has_friendship

Add friendship to ActiveRecord models
MIT License
198 stars 98 forks source link

fix migration generator to ensure distinct version numbers #17

Closed atarihomestar closed 8 years ago

atarihomestar commented 8 years ago

The addition of the add_blocker_id_to_friendships functionality meant that the migration generator now generates 2 migrations. The method to generate each template is fast enough that the 2 calls might happen within the same second, causing their version numbers to be the same. I thought of adding a sleep(1) in between the calls, but that seems kind of lame. Instead the code I changed ensures that each call to migration_template generates a name that has a unique version number. It works even if more migrations are added later.

Pensarfeo commented 8 years ago

To be honest I would prefer the sleep(1) solution. This can create conflicting migrations if other generators are used later on. Besides if a problem like this exists keeping a consistent migration number it is not something we should we take care of... After that I am out :)

sungwoncho commented 8 years ago

Thanks for pointing out and solving this issue. @Pensarfeo, thanks for your input. Adding sleep(1) is more readable, but as @atarihomestar said, making a code deliberately slow seems not the best way.

I will publish this fix because the issue might be preventing people from using the gem. But we can certainly discuss further to find a better solution.