This relates to the following question: Can Rails Migrations be used to transform data?
If I work on a branch, which, when it is reintegrated and put into production, will significantly change the database schema. What is the best way to ensure that all data in production is converted to a new format?
A simple example might be a number column, which we want to change in the text and do some data conversion work. Then we want to remove the old column.
I was advised not to do any data manipulation in migrations, but to create rake tasks for them. Is there a mechanism for rake tasks to be performed along with migrations?
Currently, the only solution I can come up with is to combine all the migrations that transfer non-existent columns into a second collection. Run the first set of migrations that add new tables. Run the rake tasks, then run the second set of migrations. This doesn’t seem like the perfect solution for me and could easily be mistaken.
source
share