|
|
|
@ -3,7 +3,8 @@ class AddIndexToUserIdAndShixunIdForShixuns < ActiveRecord::Migration[5.2]
|
|
|
|
|
shixun_members = ShixunMember.select("count(*) cnt, shixun_members.*").group(:user_id, :shixun_id).having("cnt > 1")
|
|
|
|
|
puts "shixun_members: #{shixun_members.map{|sm| sm.id}}"
|
|
|
|
|
shixun_members.each do |sm|
|
|
|
|
|
ShixunModify.find_by(id: sm.id).delete
|
|
|
|
|
s = ShixunModify.where.not(id: sm.id).where(user_id: sm.user_id, shixun_id: sm.shixun_id)
|
|
|
|
|
puts "s: #{s.map{|sm| sm.id}}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
add_index :shixun_members, [:user_id, :shixun_id], unique: true
|
|
|
|
|