Skip to content

Migrating to v0.8.0

raw1z edited this page Mar 6, 2012 · 2 revisions

If you're migrating from version prior to v0.8.0, you need to apply some changes to your database in order for it to be compatible.

  • The field user_id of the table friendships must be renamed to friendable_id.
  • The index on the table friendships must be redefined

To do that, you need to create a new migration:

rails generate migration migrate_amistad_friendships

Then add the following code in this migration:

class MigrateAmistadFriendships < ActiveRecord::Migration
  def up
    change_table :friendships do |t|
      t.remove_index :column => [:user_id, :friend_id]
      t.rename :user_id, :friendable_id
      t.index [:friendable_id, :friend_id], :unique => true
    end
  end

  def down
    change_table :friendships do |t|
      t.remove_index :column => [:friendable_id, :friend_id]
      t.rename :friendable_id, :user_id
      t.index [:user_id, :friend_id], :unique => true
    end
  end
end

Since v0.8.0, the friendship model is created automatically by amistad. The friendship model previously created in prior versions can be safely removed from the app directory. The following command does the job:

rm app/models/friendship.rb

if you need to make some changes inside the friendship model, you can apply them in an initializer. The name of the friendship model depends on the name of the user model:

'User'    => Amistad::Friendships::UserFriendship
'Profile' => Amistad::Friendships::ProfileFriendship