Hendrik Mans - March 19, 2013
rake db:pull
I have a custom Rake task called db:pull that copies sloblog.io’s production database to my local development machine. Here’s what it looks like:
As you can see, I simply ssh to my database machine, pull the contents of my production database through mysqldump, and pipe it all into my local development database.
First and foremost, I use this to quickly get some real data into my development database to test new code against. I’m a big fan of factories (my primary weapon of choice for this being FactoryGirl), and I usually set up my db/seeds.rb so it will generate production-like data, but all the Lorem Ipsum in the world is no good compared to real data created by real users.
But there’s a couple of additional uses. For example, just before I deploy a new feature that involves database migrations, I run rake db:pull followed by rake db:migrate to test my migrations against current production data.
Last but not least, this is a nice, pain-free way of quickly pulling a backup of the production database. Of course, I’m doing daily backups of the production database anyway, but sometimes I need to fiddle around in the production database, and quickly running rake db:pull makes sure I have a very recent copy in case I mess up.
Please sign in to post a comment.