diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 91cba4ab..9ce1905f 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -59,7 +59,9 @@ class WelcomeController < ApplicationController # 同步镜像 if shixun.mirror_repositories.present? shixun.mirror_repositories.each do |mirror| - LocalMirrorRepository.create!(:local_shixun_id => local_shixun.id, :mirror_repository_id => mirror.id) + # 本地版的mirror id和线上的可能不一样,所以按名字取,然后再存 + # local_mirror = MirrorRepository.where(type_name: mirror.type_name).first.try(:id) + LocalMirrorRepository.create!(:local_shixun_id => local_shixun.id, :mirror_repository_id => mirror.id, type_name: mirror.type_name) end end @@ -124,7 +126,8 @@ class WelcomeController < ApplicationController local_mirrors = LocalMirrorRepository.where(local_shixun_id: local_shixun.id) if local_mirrors.present? local_mirrors.each do |local_mirror| - ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => local_mirror.mirror_repository_id) + local_mirror_new = MirrorRepository.where(type_name: local_mirror.try(:type_name)).first + ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => local_mirror_new.id) end end diff --git a/db/migrate/20190507031028_add_type_name_to_local_mirror_repositories.rb b/db/migrate/20190507031028_add_type_name_to_local_mirror_repositories.rb new file mode 100644 index 00000000..ce6ff3b3 --- /dev/null +++ b/db/migrate/20190507031028_add_type_name_to_local_mirror_repositories.rb @@ -0,0 +1,5 @@ +class AddTypeNameToLocalMirrorRepositories < ActiveRecord::Migration + def change + add_column :local_mirror_repositories, :type_name, :string + end +end