diff --git a/db/migrate/20110707234802_likes_on_comments.rb b/db/migrate/20110707234802_likes_on_comments.rb index 693b3dfdd..9a65d66c4 100644 --- a/db/migrate/20110707234802_likes_on_comments.rb +++ b/db/migrate/20110707234802_likes_on_comments.rb @@ -1,4 +1,5 @@ class LikesOnComments < ActiveRecord::Migration + class Likes < ActiveRecord::Base; end def self.up remove_foreign_key :likes, :posts @@ -11,7 +12,17 @@ class LikesOnComments < ActiveRecord::Migration UPDATE likes SET target_type = 'Post' SQL + execute < 1') + keeper_likes.each do |like| + l = Like.arel_table + Like.where(:target_id => like.target_id, :author_id => like.author_id, :target_type => like.target_type).where(l[:id].not_eq(like.id)).delete_all + end add_index :likes, [:target_id, :author_id, :target_type], :unique => true end