You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/db/migrate/20190703090511_add_index_fo...

10 lines
671 B

5 years ago
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
5 years ago
add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique"
end
end