andrunix
andrunix

Reputation: 1754

Should I use a Rails Migration to update production data?

In an old Rails application, I need to update one column in a set of records in a production database. I am not altering the structure of the database in any way. I could just write a SQL script that runs against the database or I could write a Rails migration that updates all the models that need to be changed. However, this just doesn't feel right.

What is the best practice for one-off database updates that only modify production data, no structure changes?

Upvotes: 1

Views: 622

Answers (1)

Saurabh
Saurabh

Reputation: 73659

As par rubyonrails guide:

Migrations are a convenient way to alter your database schema over time in a consistent and easy way.

I think you should have script for data-fixes, as these are one time fixes, and you wouldn't want those to run, if somebody runs migrations on some other migration or on local each time while testing, etc. Migration should only contain the code which changes your database schema in any way not data.

Edited

It seems that rails has eveolved over the time and now it suggests that migrations can be used to add/modify data, from edgeguides:

The main purpose of Rails' migration feature is to issue commands that modify the schema using a consistent process. Migrations can also be used to add or modify data. This is useful in an existing database that can't be destroyed and recreated, such as a production database.

Upvotes: 3

Related Questions