From ab9b9b2fa0fe8a1b10a911c914bff24aa0744b58 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 17:52:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190703090511_add_index_for_shixun_services.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb index 3e6dd3703..693add3e3 100644 --- a/db/migrate/20190703090511_add_index_for_shixun_services.rb +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -1,5 +1,9 @@ class AddIndexForShixunServices < ActiveRecord::Migration[5.2] def change + sql = %Q(delete from shixun_service_configs where (shixun_id, mirror_repository_id) in + (select * from (select shixun_id, mirror_repository_id from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1) a) + and id not in (select * from (select min(id) from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1 order by id) b)) + ActiveRecord::Base.connection.execute sql add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" end end