Reputation: 1920
I have a well-running production environment. For purposes of testing, I want to copy all database tables (including table content!) to my test environment.
I tried rake db:test:clone
, but this only creates the table structures, not the contents.
Is there a rake task or something comparable for this?
Upvotes: 2
Views: 3904
Reputation: 3792
You could use the yml_db gem. Just do the following:
gem 'yaml_db'
bundle exec rake db:data:dump RAILS_ENV=production
*Note you need to do this from a console that can access your production database using the settings in database.yml (or wherever you have them). I was able to set up a ssh tunnel to my prod server and then just run the command locally but you may need to run it from the server and then download the /db/data.yml file.
bundle exec rake db:data:dump RAILS_ENV=development
If your db isn't empty and migrated just run rake reset
first.
Read this post for more info.
Upvotes: 0
Reputation: 5961
Take a look on : https://github.com/napcs/lazy_developer
also you can check : http://blog.robseaman.com/2008/12/2/production-data-to-development
And
Upvotes: 0
Reputation: 8034
You can use taps gem as showed here: http://railscasts.com/episodes/342-migrating-to-postgresql
Upvotes: 0
Reputation: 9577
I don't think there is something that you want, but I'm not sure why you'd want that knowing how test environments work, that'd you want it to happen. You basically want a shell command to restore from a dump.
In the testing environment, your database is broken down and rebuilt "basically" after each test is ran. It will load up your fixtures/factories and then apply the test that it runs. The thought with the testing environment is that you test everything in isolation, unless they are integration tests which have a sense of what 'some other test' did previously.
Now all that to say, if your production data is large, it may suck to build that big production data each time.
If the data is essential, copy it into a fixture or factory and you'll have the same data repeatable.
Is there a smaller reason why you want the whole DB and not just one or two pieces of the data?
Upvotes: 0