2

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?

5 Answers 5

1

Try this one:

rake db:test:prepare
Sign up to request clarification or add additional context in comments.

1 Comment

Didn´t help. By description this task "Checks for pending migrations and loads the test schema".
0

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?

Comments

0

You can use taps gem as showed here: http://railscasts.com/episodes/342-migrating-to-postgresql

Comments

0

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

Comments

0

You could use the yml_db gem. Just do the following:

  1. Include the following in your gemfile and run bundle install

gem 'yaml_db'

  1. Create a dump file of your current 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.

  1. Assuming your dump file is now in /db/data.yml and you have an empty migrated db you can run the following

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.