parent
f940ba5b89
commit
ab9b9b2fa0
@ -1,5 +1,9 @@
|
|||||||
class AddIndexForShixunServices < ActiveRecord::Migration[5.2]
|
class AddIndexForShixunServices < ActiveRecord::Migration[5.2]
|
||||||
def change
|
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"
|
add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in new issue