has-friendship / has_friendship

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

Migration Error #67

Open ughstudios opened 5 years ago

ughstudios commented 5 years ago

ArgumentError: Algorithm must be one of the following: :default, :copy, :inplace

I get this when I simply run rails db:migrate

chevinbrown commented 5 years ago

@Bdoom can you provide more info? What version of rails? Is this the latest gem version? What database?

ughstudios commented 5 years ago

I'm using mysql, the latest gem version, and rails 5.2.3 ruby version 2.6.3.

chevinbrown commented 5 years ago

That's definitely a bug. I probably won't have time to get to the mysql version of it for a bit. Would you feel comfortable offering a PR?

ughstudios commented 5 years ago

I would if I can find the solution first. I think it's just this line: add_index :friendships, [:friendable_id, :friend_id], unique: true, algorithm: :concurrently

Do you know what I need to change?

ughstudios commented 5 years ago

Entire migration:


# This migration comes from has_friendship_engine (originally 4)
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
  class AddUniqueIndexToFriendships < ActiveRecord::Migration[4.2]; end
else
  class AddUniqueIndexToFriendships < ActiveRecord::Migration; end
end

AddUniqueIndexToFriendships.class_eval do
  disable_ddl_transaction!

  def self.up
    return if index_exists?(:friendships, [:friendable_id, :friend_id])

    add_index :friendships, [:friendable_id, :friend_id], unique: true, algorithm: :concurrently
  end

  def self.down
    return unless index_exists?(:friendships, [:friendable_id, :friend_id])

    remove_index :friendships, [:friendable_id, :friend_id]
  end
end
ughstudios commented 5 years ago

Would it be default, copy, or in place?

ughstudios commented 5 years ago

Looks like :concurrently is simply only for Postgres databases actually. I think I could just use :inplace for now. But from what I can tell, :concurrently actually speeds up your database a lot lol. Maybe I'll move to postgres haha

chevinbrown commented 5 years ago

Yeah, mysql & postgres have different strategies. If your db-size is relatively small, you'll be fine without concurrency and won't really notice a difference.

It looks like we'll need to set the algorithm dynamically depending on the db-type. :/

ughstudios commented 5 years ago

I just installed postgres and it worked fine. I'm not really attached to mysql, it was just easiest to install.