Upcoming and OnDemand Webinars View full list

(safely) Playing with your production data

Derek

Sometimes our Ruby on Rails apps work perfectly with test data, but when they go to production, errors creep in. Debugging errors on a production server is a pain and a bit dangerous.

Here’s what we do to quickly and safely debug issues on our production servers:

1. Add the following capistrano task to create an SQL dump of your data. If it’s a large database, it may be worthwhile to compress the SQL dump as well.

 desc "Exports the production db to the home directory of user" task :db_dump, :roles => [:app, :db] do   run("mysqldump -u #{database_username} --password=#{database_password} #{application}_production > production.sql") end 

2. Create the following rake tasks to grab database dump and import the data locally.

 namespace :db do   desc 'Grab a dump of the production database on the server and places it in db/production.sql.'   task :get_production do      `cap db_dump`     `scp DEPLOY_USER@SERVER_NAME.slingshothosting.com:production.sql #{RAILS_ROOT}/db/production.sql`   end      desc 'Imports the database dump of file db/production.sql into development.'   task :import do      `mysql -u root app_name_development < db/production.sql`   end      desc 'Grabs a dump of the production database from the server and imports the data into the local development database.'   task :get_import => [ :get_production, :import ] end 

3. Install the Firefox plugin Server Switcher to make it easy to switch between the production and local server in your web browser.

4. Disable mail in your development box – it’s not a good feeling when you realize you’ve emailed several thousand users while testing out a newsletter script.

 config.action_mailer.delivery_method = :test 

Not Happy with Your Current App, or Digital Product?

Submit your event

Let's Discuss Your Project

Let's Discuss Your Project