简体   繁体   中英

Different environments for one rake task in Rails

is it possible to call a rake task on different environments? That means I have a production database where I want to read out some data and put it to my test database.

The tables in my test database are unknown in the production database and vice versa.

EDIT: they are both NOT my standard environment, so both are not local.

You can check octopus , it's a gem that allows you to choose the database that the query will call, you could use it to specify in your rake from where to read out and put data.

So in your rake, you could do something like (may not be the best way):

@user = User.where(:name => "Test").using(:production_one)
@duplicate_user = @user.dup
Octopus.using(:test_one) do
  @duplicate_user.save
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM