Mongoid 데이터베이스가있는 레일 4 애플리케이션이 있으며 테스트 용도로 샌드 박스 환경을 도입하려고합니다. 프로덕션 db에서 샌드 박스로 복사하려는 일부 데이터 (두 모델)가 있습니다.데이터베이스 간 레이크 작업
나는 cronjob이 호출하는 레이크 작업으로이 작업을 수행합니다. 그러나이 레이크 작업에서는 데이터베이스에 두 개의 연결을 설정하는 방법과 다른 데이터베이스에 대해 동일한 모델을 사용하는 방법을 잘 모릅니다.
나는 mongodb 레이어 (여기서는 How to copy a collection from one database to another in MongoDB처럼)에서 생각하고 있었지만 한 모델은 샌드 박스 데이터베이스에만 부분적으로 복사해야하는 데이터로 구성되어 있습니다. 따라서 Rails 환경에서해야한다고 생각합니다.
namespace :sandbox do
desc "Syncs production -> sandbox data"
task(:sync => :environment) do |t, args|
Article.all.each do |article|
if my_model1.state == :active
# here it should sync article to the sandbox models
# and then, it should also sync all the comments to the sandbox models
article.comments
end
end
end
end
end