Rails : Best practices to change data in Production database

The situation might come when the whole data-column in few tables of production database have to be altered. Most probably when you forgot to set default value in data-fields and stored Null value is troubling you when querying.

If you are willing to change the data in production

  • SSH into you production environment
  • CHDir to your current deployment dir open Rails Console in --sandbox mode See here for more detail about rails console http://edgeguides.rubyonrails.org/command_line.html#rails-console
  • Apply the changes you desire and verify the changes if it is as you expected
  • if it is as you expected, type all the commands in notepad with ; at the end of every statement or proper line-feed
  • After that copy all the commands at once..
  • open Rails console in normal mode and execute the commands at once

Rails console in Sandbox mode: Any changes you make is rolled back after you exit the console.
And, Changing data in production without verifying properly could cost you a fortune. so be careful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s