Replicate is a Gem that lets you dump and load relational objects between Ruby/Ruby on Rails environments, e.g. dump data from your production database and load it in your development database.
The examples given in the README are of shell scripts being used to do this. I wanted to use a Capistrano task because it keeps everything related to the production site in one place (particularly the config).
Note: This is tested on a relatively small data set yet it still took about 20 seconds to run - YMMV!
- Add the code below to your
config/deploy.rb
- Alter the
code = ENV["DATA"] || "User.all; Project.all"
line to list all the data you want dumped by default - Run
cap db:replicate
to download all data from the production site - Run
cap -e db:replicate
to see the full usage instructions
- Steam the data directly from the dumper to the loader instead of holding it in a temporary variable
- Automatically dump all tables instead of requiring them to be listed manually
- Improve the DATA variable parsing - currently this is not possible:
Character.find_by_name(";")
because the;
is treated as a command separator