I need to update a table data in database using RAILS migrations.
Sample:
Table: Table_A(Col_A(number), Col_B(varchar),...)
Query: UPDATE Table_A SET Col_B = "XXX" where Col_B = "YYY"
What would be the best way to do this using RAILS Migrations. I am not even sure if RAILS migrations is the way to go for updating data in database. Any explanation would be helpful.
It's usually better to do these sorts of big data updates in a rake task. I usually write them so they have two versions: rake change_lots_of_data:report and rake change_lots_of_data:update. The 'report' version just executes the where clause and spits out a list of what would be changed. The 'update' version uses the very same where clause but makes the changes.
Some advantages of doing it this way are: