From 514ceaf73eecc3bb6c0bccbf7c9c470606ea254a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 14 Feb 2020 10:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...add_index_to_user_id_and_shixun_id_for_shixuns.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/migrate/20200214022547_add_index_to_user_id_and_shixun_id_for_shixuns.rb diff --git a/db/migrate/20200214022547_add_index_to_user_id_and_shixun_id_for_shixuns.rb b/db/migrate/20200214022547_add_index_to_user_id_and_shixun_id_for_shixuns.rb new file mode 100644 index 000000000..66e72a274 --- /dev/null +++ b/db/migrate/20200214022547_add_index_to_user_id_and_shixun_id_for_shixuns.rb @@ -0,0 +1,12 @@ +class AddIndexToUserIdAndShixunIdForShixuns < ActiveRecord::Migration[5.2] + def change + 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 + end + + add_index :shixun_members, [:user_id, :shixun_id], unique: true + + end +end